github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume3/section4/gopherface/common/datastore/datastore.go (about)

     1  package datastore
     2  
     3  import "github.com/EngineerKamesh/gofullstack/volume3/section4/gopherface/models"
     4  
     5  type Datastore interface {
     6  	CreateUser(user *models.User) error
     7  	GetUser(username string) (*models.User, error)
     8  	Close()
     9  }
    10  
    11  const (
    12  	MYSQL = iota
    13  	MONGODB
    14  	REDIS
    15  )
    16  
    17  func NewDatastore(datastoreType int, dbConnectionString string) (Datastore, error) {
    18  
    19  	switch datastoreType {
    20  	case MYSQL:
    21  		return NewMySQLDatastore(dbConnectionString)
    22  	case MONGODB:
    23  		return NewMongoDBDatastore(dbConnectionString)
    24  	case REDIS:
    25  		return NewRedisDatastore(dbConnectionString)
    26  
    27  	}
    28  
    29  	return nil, nil
    30  }