Ejemplo n.º 1
0
// 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)
}
Ejemplo n.º 2
0
// 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")
	}
}
Ejemplo n.º 3
0
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
}
Ejemplo n.º 4
0
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
}
Ejemplo n.º 5
0
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
}
Ejemplo n.º 6
0
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
}
Ejemplo n.º 7
0
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
}