Return if any errors when initialising data stores
This commit is contained in:
parent
538a214e82
commit
f26c4862a5
4 changed files with 18 additions and 3 deletions
|
@ -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)
|
||||
|
|
12
kvs/db.go
12
kvs/db.go
|
@ -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}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue