Skip to content

Commit

Permalink
fix: PGSQL JDBC password parsing (#10)
Browse files Browse the repository at this point in the history
* fix: PGSQL JDBC password parsing

* fix: missing imports

* perf: db connection parameters via env vars
  • Loading branch information
andhreljaKern authored Aug 29, 2024
1 parent fcfb87c commit 20883f3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"flag"
"log"
"net/http"
Expand All @@ -14,6 +15,12 @@ var addr = flag.String("addr", ":8080", "http service address")

var (
Logger *log.Logger
host string = os.Getenv("DB_HOST")
port string = os.Getenv("DB_PORT")
user string = os.Getenv("DB_USER")
password string = os.Getenv("DB_PASSWORD")
dbname string = os.Getenv("DB_NAME")
params string = os.Getenv("DB_PARAMS")
)

func main() {
Expand All @@ -38,7 +45,10 @@ func main() {
}

func getOrganizationId(userId string) string {
db, dberr := sql.Open("postgres", os.Getenv("DB_DSN"))
psqlInfo := fmt.Sprintf(
"host=%s port=%s user=%s password=%s dbname=%s %s",
host, port, user, password, dbname, params)
db, dberr := sql.Open("postgres", psqlInfo)
if dberr != nil {
log.Fatal("Failed to open a DB connection: ", dberr)
}
Expand Down

0 comments on commit 20883f3

Please sign in to comment.