Fixed schemas

This commit is contained in:
cdricms
2025-01-15 09:29:18 +01:00
parent 354f8cc02e
commit d18245736f
2 changed files with 40 additions and 22 deletions

View File

@@ -10,11 +10,8 @@ import (
"context"
"database/sql"
_ "github.com/lib/pq"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect/pgdialect"
"github.com/uptrace/bun/driver/pgdriver"
)
func handler(w http.ResponseWriter, r *http.Request) {
@@ -32,7 +29,7 @@ type DSN struct {
}
func (dsn *DSN) ToString() string {
return fmt.Sprintf("posgres://%s:%s@%s:%s/%s?sslmode=disable", dsn.User, dsn.Password, dsn.Hostname, dsn.Port, dsn.DBName)
return fmt.Sprintf("postgres://%s:%s@%s:%s/%s?sslmode=disable", dsn.User, dsn.Password, dsn.Hostname, dsn.Port, dsn.DBName)
}
func handlerCreateUser(w http.ResponseWriter, r *http.Request) {
@@ -69,13 +66,15 @@ func main() {
dsn := DSN{
Hostname: "localhost",
Port: port,
Port: os.Getenv("POSTGRES_PORT"),
DBName: os.Getenv("POSTGRES_DB"),
User: os.Getenv("POSTGRES_USER"),
Password: os.Getenv("POSTGRES_PASSWORD"),
}
sqldb := sql.OpenDB(pgdriver.NewConnector(pgdriver.WithDSN(dsn.ToString())))
DB = bun.NewDB(sqldb, pgdialect.New())
DB, err = InitDatabase(dsn)
if err != nil {
log.Fatal(err)
}
http.HandleFunc("/", handler)