package database import ( "database/sql" "fmt" "log" "os" _ "github.com/jackc/pgx/v5/stdlib" _ "github.com/joho/godotenv/autoload" ) var ( database = os.Getenv("DB_DATABASE") password = os.Getenv("DB_PASSWORD") username = os.Getenv("DB_USERNAME") port = os.Getenv("DB_PORT") host = os.Getenv("DB_HOST") schema = os.Getenv("DB_SCHEMA") dbInstance *service ) func New() Service { if dbInstance != nil { return dbInstance } connStr := fmt.Sprintf("postgresql://%s:%s@%s:%s/%s?sslmode=verify-full", username, password, host, port, database) db, err := sql.Open("pgx", connStr) if err != nil { log.Fatal(err) } dbInstance = &service{ db: db, } return dbInstance }