mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
Fix pgx configuration
This commit is contained in:
parent
0c64d9b15d
commit
dc41880ca7
38
auth/main.go
38
auth/main.go
@ -15,8 +15,7 @@ import (
|
|||||||
"github.com/go-playground/validator/v10"
|
"github.com/go-playground/validator/v10"
|
||||||
"github.com/golang-migrate/migrate/v4"
|
"github.com/golang-migrate/migrate/v4"
|
||||||
pgxd "github.com/golang-migrate/migrate/v4/database/pgx/v5"
|
pgxd "github.com/golang-migrate/migrate/v4/database/pgx/v5"
|
||||||
"github.com/jackc/pgx/v5"
|
_ "github.com/golang-migrate/migrate/v4/source/file"
|
||||||
"github.com/jackc/pgx/v5/pgconn"
|
|
||||||
"github.com/jackc/pgx/v5/pgxpool"
|
"github.com/jackc/pgx/v5/pgxpool"
|
||||||
"github.com/jackc/pgx/v5/stdlib"
|
"github.com/jackc/pgx/v5/stdlib"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
@ -60,30 +59,26 @@ func OpenDatabase() (*pgxpool.Pool, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.New("invalid postgres port specified")
|
return nil, errors.New("invalid postgres port specified")
|
||||||
}
|
}
|
||||||
conf := pgxpool.Config{
|
|
||||||
ConnConfig: &pgx.ConnConfig{
|
config, _ := pgxpool.ParseConfig("")
|
||||||
Config: pgconn.Config{
|
config.ConnConfig.Host = os.Getenv("POSTGRES_SERVER")
|
||||||
Host: os.Getenv("POSTGRES_SERVER"),
|
config.ConnConfig.Port = uint16(port)
|
||||||
Port: uint16(port),
|
config.ConnConfig.Database = os.Getenv("POSTGRES_DB")
|
||||||
Database: os.Getenv("POSTGRES_DB"),
|
config.ConnConfig.User = os.Getenv("POSTGRES_USER")
|
||||||
User: os.Getenv("POSTGRES_USER"),
|
config.ConnConfig.Password = os.Getenv("POSTGRES_PASSWORD")
|
||||||
Password: os.Getenv("POSTGRES_PASSWORD"),
|
config.ConnConfig.TLSConfig = nil
|
||||||
TLSConfig: nil,
|
config.ConnConfig.RuntimeParams = map[string]string{
|
||||||
RuntimeParams: map[string]string{
|
|
||||||
"application_name": "keibi",
|
"application_name": "keibi",
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
schema := os.Getenv("POSTGRES_SCHEMA")
|
schema := os.Getenv("POSTGRES_SCHEMA")
|
||||||
if schema == "" {
|
if schema == "" {
|
||||||
schema = "keibi"
|
schema = "keibi"
|
||||||
}
|
}
|
||||||
if schema != "disabled" {
|
if schema != "disabled" {
|
||||||
conf.ConnConfig.RuntimeParams["search_path"] = schema
|
config.ConnConfig.RuntimeParams["search_path"] = schema
|
||||||
}
|
}
|
||||||
|
|
||||||
db, err := pgxpool.NewWithConfig(ctx, &conf)
|
db, err := pgxpool.NewWithConfig(ctx, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Could not connect to database, check your env variables!")
|
fmt.Printf("Could not connect to database, check your env variables!")
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -97,7 +92,10 @@ func OpenDatabase() (*pgxpool.Pool, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
driver, err := pgxd.WithInstance(stdlib.OpenDBFromPool(db), &pgxd.Config{})
|
dbi := stdlib.OpenDBFromPool(db)
|
||||||
|
defer dbi.Close()
|
||||||
|
|
||||||
|
driver, err := pgxd.WithInstance(dbi, &pgxd.Config{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -107,7 +105,7 @@ func OpenDatabase() (*pgxpool.Pool, error) {
|
|||||||
}
|
}
|
||||||
m.Up()
|
m.Up()
|
||||||
|
|
||||||
return db, nil
|
return db, err
|
||||||
}
|
}
|
||||||
|
|
||||||
type Handler struct {
|
type Handler struct {
|
||||||
@ -135,7 +133,7 @@ func main() {
|
|||||||
|
|
||||||
db, err := OpenDatabase()
|
db, err := OpenDatabase()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e.Logger.Fatal(err)
|
e.Logger.Fatal("Could not open databse: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user