// Init data store. func Init(driver, url, dbname string) { log.Info("init data store") d, ok := drivers[strings.ToLower(driver)] if !ok { log.Fatal("unknown database driver") } s, err := d.Open(url, dbname) if err != nil { log.Fatal("unable to connect to %s database with %s: %+v", driver, url, err) } setStore(s) }
// setStore initializes global data store func setStore(s Store) { if s == nil { log.Fatal("data store is not initialized") } log.Info("data store initialized") store = s cleanup = func() { store.Close() log.Info("data store closed") } }
func makeRedisStore() data.Store { flag.Parse() const ( url = "tcp://127.0.0.1:6379/15" ) var store, err = redis.Open(url, true) if err != nil { log.Fatal("unable to connect to redis with %s: %+v", url, err) } return store }
func makeBoltStore() data.Store { flag.Parse() const ( path = "test.db" ) var store, err = boltdb.Open(path, true) if err != nil { log.Fatal("unable to connect to database with %s: %+v", path, err) } return store }
func makeLedisStore() data.Store { flag.Parse() const ( path = "data" db = 0 ) var store, err = ledis.Open(path, db, true) if err != nil { log.Fatal("unable to connect to database with %s: %+v", path, err) } return store }
func makePgStore() data.Store { flag.Parse() const ( dburl = "user=postgres password=$PGPWD sslmode=disable" dbname = "test" ) var store, err = postgresql.Open(dburl, dbname, true) if err != nil { log.Fatal("unable to connect to database with %s: %+v", dburl, err) } return store }
func makeMongoStore() data.Store { flag.Parse() const ( dburl = "127.0.0.1" dbname = "test" ) var store, err = mongo.Open(dburl, dbname, true) if err != nil { log.Fatal("unable to connect to database with %s: %+v", dburl, err) } return store }