mirror of
https://github.com/riwiwa/muzi.git
synced 2026-02-28 11:56:57 -08:00
clean up main.go
This commit is contained in:
11
db/db.go
11
db/db.go
@@ -21,9 +21,18 @@ func CreateAllTables() error {
|
||||
return CreateSessionsTable()
|
||||
}
|
||||
|
||||
func GetDbUrl() string {
|
||||
host := os.Getenv("PGHOST")
|
||||
port := os.Getenv("PGPORT")
|
||||
user := os.Getenv("PGUSER")
|
||||
pass := os.Getenv("PGPASSWORD")
|
||||
|
||||
return fmt.Sprintf("postgres://%s:%s@%s:%s", user, pass, host, port)
|
||||
}
|
||||
|
||||
func CreateDB() error {
|
||||
conn, err := pgx.Connect(context.Background(),
|
||||
"postgres://postgres:postgres@localhost:5432",
|
||||
GetDbUrl(),
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Cannot connect to PostgreSQL: %v\n", err)
|
||||
|
||||
Reference in New Issue
Block a user