github.com/EngineerKamesh/gofullstack@v0.0.0-20180609171605-d41341d7d4ee/volume2/section5/gopherfacedb/common/datastore/datastore.go (about) 1 package datastore 2 3 import ( 4 "errors" 5 6 "github.com/EngineerKamesh/gofullstack/volume2/section5/gopherfacedb/models" 7 ) 8 9 type Datastore interface { 10 CreateUser(user *models.User) error 11 GetUser(username string) (*models.User, error) 12 Close() 13 } 14 15 const ( 16 MYSQL = iota 17 MONGODB 18 REDIS 19 ) 20 21 func NewDatastore(datastoreType int, dbConnectionString string) (Datastore, error) { 22 23 switch datastoreType { 24 case MYSQL: 25 return NewMySQLDatastore(dbConnectionString) 26 case MONGODB: 27 return NewMongoDBDatastore(dbConnectionString) 28 case REDIS: 29 return NewRedisDatastore(dbConnectionString) 30 default: 31 return nil, errors.New("The datastore you specified does not exist!") 32 } 33 34 }