21 lines
401 B
Go
21 lines
401 B
Go
package app
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
"github.com/jackc/pgx/v5/stdlib"
|
|
"github.com/jmoiron/sqlx"
|
|
)
|
|
|
|
func (a *App) initPostgres() {
|
|
if a.config.postgresURI == "" {
|
|
return
|
|
}
|
|
pool, err := pgxpool.New(a.ctx, a.config.postgresURI)
|
|
if err != nil {
|
|
log.Fatalln("failed to connect to postgres:", err)
|
|
}
|
|
a.postgres = sqlx.NewDb(stdlib.OpenDBFromPool(pool), "postgres")
|
|
}
|