21 lines
470 B
Go

package main
import (
"os"
"context"
"github.com/jackc/pgx/v4/pgxpool"
"log"
)
var pool *pgxpool.Pool
func getDbPool() *pgxpool.Pool {
// Setup Database
dburl := "postgres://" + os.Getenv("POSTGRES_USER") + ":" + os.Getenv("POSTGRES_PASSWORD") + "@" + os.Getenv("POSTGRES_HOSTNAME") + "/" + os.Getenv("POSTGRES_DB")
pool, err := pgxpool.Connect(context.Background(), dburl)
if err != nil {
log.Fatal("Unable to connect to database:", err)
}
return pool
}