Skip to content

Commit

Permalink
Add ping to db connection
Browse files Browse the repository at this point in the history
  • Loading branch information
Piszmog committed May 1, 2024
1 parent b705eb2 commit 588f21d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions db/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ type Database interface {
}

func New(logger *slog.Logger, opts DatabaseOpts) (Database, error) {
var db Database
var err error
if opts.Token == "" {
return newLocalDB(logger, opts.URL)
db, err = newLocalDB(logger, opts.URL)
} else {
return newRemoteDB(logger, opts.URL, opts.Token)
db, err = newRemoteDB(logger, opts.URL, opts.Token)
}
if err != nil {
return nil, err
}
if err = db.DB().Ping(); err != nil {
return nil, err
}
return db, nil
}

type DatabaseOpts struct {
Expand Down

0 comments on commit 588f21d

Please sign in to comment.