Refactor link repository and improve logging
This commit is contained in:
parent
ddaf0dcbfc
commit
458ae28901
7 changed files with 63 additions and 19 deletions
|
|
@ -6,16 +6,34 @@ import (
|
|||
"fmt"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/knadh/koanf"
|
||||
"github.com/rs/zerolog/log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Pool(config *koanf.Koanf) *pgxpool.Pool {
|
||||
connStr, err := getConnectionString(config)
|
||||
if err != nil {
|
||||
func InitPool(config *koanf.Koanf) *pgxpool.Pool {
|
||||
pool := NewPool(config)
|
||||
|
||||
if err := runMigrations(pool); err != nil {
|
||||
log.Fatal().Err(err).Msg("Couldn't apply migrations")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
pool, err := pgxpool.Connect(context.Background(), connStr)
|
||||
return pool
|
||||
}
|
||||
|
||||
func NewPool(config *koanf.Koanf) *pgxpool.Pool {
|
||||
connStr, err := getConnectionString(config)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Couldn't construct DB connection string")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
|
||||
pool, err := pgxpool.Connect(ctx, connStr)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Couldn't connect to DB")
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue