Return if any errors when initialising data stores

This commit is contained in:
Tobie Morgan Hitchcock 2016-07-19 10:22:22 +01:00
parent 538a214e82
commit f26c4862a5
4 changed files with 18 additions and 3 deletions

View file

@ -36,6 +36,9 @@ func New(opts *cnf.Options) (ds kvs.DS, err error) {
path := strings.TrimLeft(opts.DB.Path, "boltdb://")
db, err = bolt.Open(path, 0666, nil)
if err != nil {
return
}
db.Update(func(tx *bolt.Tx) error {
tx.CreateBucketIfNotExists(bucket)

View file

@ -35,15 +35,21 @@ func New(opts *cnf.Options) (db *DB, err error) {
var ds DS
if strings.HasPrefix(opts.DB.Path, "boltdb://") {
ds, err = stores["boltdb"](opts)
if ds, err = stores["boltdb"](opts); err != nil {
return
}
}
if strings.HasPrefix(opts.DB.Path, "mysql://") {
ds, err = stores["mysql"](opts)
if ds, err = stores["mysql"](opts); err != nil {
return
}
}
if strings.HasPrefix(opts.DB.Path, "pgsql://") {
ds, err = stores["pgsql"](opts)
if ds, err = stores["pgsql"](opts); err != nil {
return
}
}
db = &DB{ds: ds}

View file

@ -35,6 +35,9 @@ func New(opts *cnf.Options) (ds kvs.DS, err error) {
path := strings.TrimLeft(opts.DB.Path, "mysql://")
db, err = sql.Open("mysql", path)
if err != nil {
return
}
return &DS{db: db, ck: opts.DB.Key}, err

View file

@ -35,6 +35,9 @@ func New(opts *cnf.Options) (ds kvs.DS, err error) {
path := strings.TrimLeft(opts.DB.Path, "pgsql://")
db, err = sql.Open("postgres", path)
if err != nil {
return
}
return &DS{db: db, ck: opts.DB.Key}, err