Last active
July 25, 2019 12:05
-
-
Save jfeng45/5b141ec3b18118f526b88e5b23914c7c to your computer and use it in GitHub Desktop.
database factory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// To map "database code" to "database interface builder" | |
// Concreate builder is in corresponding factory file. For example, "sqlFactory" is in "sqlFactory".go | |
var dsFbMap = map[string]dsFbInterface{ | |
config.SQLDB: &sqlFactory{}, | |
config.COUCHDB: &couchdbFactory{}, | |
config.CACHE_GRPC: &cacheGrpcFactory{}, | |
} | |
// DataStoreInterface serve as a marker to indicate the return type for Build method | |
type DataStoreInterface interface{} | |
// The builder interface for factory method pattern | |
// Every factory needs to implement Build method | |
type dsFbInterface interface { | |
Build(container.Container, *config.DataStoreConfig) (DataStoreInterface, error) | |
} | |
//GetDataStoreFb is accessors for factoryBuilderMap | |
func GetDataStoreFb(key string) dsFbInterface { | |
return dsFbMap[key] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment