22 lines
479 B
Go

package main
import (
"os"
"context"
"log"
"fmt"
"github.com/jackc/pgx/v4/pgxpool"
)
var pool *pgxpool.Pool
func getDbPool() *pgxpool.Pool {
// Setup Database
dburl := fmt.Sprintf("postgres://%s:%s@%s/%s", 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
}