22 lines
479 B
Go
Raw Normal View History

2021-02-13 02:49:36 +00:00
package main
import (
"os"
2021-02-13 02:49:36 +00:00
"context"
"log"
2025-01-28 16:34:33 +00:00
"fmt"
"github.com/jackc/pgx/v4/pgxpool"
2021-02-13 02:49:36 +00:00
)
var pool *pgxpool.Pool
func getDbPool() *pgxpool.Pool {
// Setup Database
2025-01-28 16:34:33 +00:00
dburl := fmt.Sprintf("postgres://%s:%s@%s/%s", os.Getenv("POSTGRES_USER"), os.Getenv("POSTGRES_PASSWORD"), os.Getenv("POSTGRES_HOSTNAME"), os.Getenv("POSTGRES_DB"))
2025-01-24 21:30:25 +00:00
pool, err := pgxpool.Connect(context.Background(), dburl)
2021-02-13 02:49:36 +00:00
if err != nil {
log.Fatal("Unable to connect to database:", err)
2021-02-13 02:49:36 +00:00
}
return pool
}