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