Fixed schemas
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user