Ejemplo n.º 1
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.º 2
0
// RegisterDriver regisers new driver with given names.
func RegisterDriver(driver Driver, knownNames ...string) {
	for _, k := range knownNames {
		k = strings.TrimSpace(k)
		if len(k) == 0 {
			continue
		}
		drivers[strings.ToLower(k)] = driver
	}
	log.Info("registered data store driver: %v", knownNames)
}
Ejemplo n.º 3
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)
}