orbis/internal/app/postgres.go
kjuulh f2ef496b82
All checks were successful
continuous-integration/drone/push Build is passing
add basic leader election on top of postgres
2025-01-06 23:19:03 +01:00

24 lines
481 B
Go

package app
import (
"context"
"fmt"
"os"
"time"
"git.front.kjuulh.io/kjuulh/orbis/internal/utilities"
"github.com/jackc/pgx/v5"
)
var Postgres = utilities.Singleton(func() (*pgx.Conn, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
conn, err := pgx.Connect(ctx, os.Getenv("ORBIS_POSTGRES_DB"))
if err != nil {
return nil, fmt.Errorf("failed to connect to orbis postgres database: %w", err)
}
return conn, nil
})