Skip to content

Commit

Permalink
Read database dsn like other flags
Browse files Browse the repository at this point in the history
  • Loading branch information
thesoulless committed Dec 24, 2024
1 parent 205bdff commit 183fd62
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
)

var (
host, port, email, domain, certKey, cert string
dev bool
indexPage, deletePage []byte
decPageTmpl *template.Template
db *sqlx.DB
host, port, email, domain, certKey, cert, database_url string
dev bool
indexPage, deletePage []byte
decPageTmpl *template.Template
db *sqlx.DB

visitFile *os.File
visits = make(map[string]int)
Expand Down Expand Up @@ -70,7 +70,7 @@ func run() error {
setupFlags()

var err error
db, err = sqlx.Open("pgx", os.Getenv("DATABASE_URL"))
db, err = sqlx.Open("pgx", database_url)
if err != nil {
slog.Error("failed connect to the db", "error", err)
os.Exit(1)
Expand Down Expand Up @@ -402,6 +402,7 @@ func setupFlags() {
flag.StringVar(&port, "port", "80", "port to run the server")
flag.StringVar(&email, "email", "", "email to be used by autocert")
flag.StringVar(&domain, "domain", "http://127.0.0.1", "domain with schema (and port if needed) to be used for url generation")
flag.StringVar(&database_url, "database-url", "", "database url")
flag.StringVar(&certKey, "cert-key", "", "certificate key file")
flag.StringVar(&cert, "cert", "", "certificate file")
flag.Parse()
Expand Down

0 comments on commit 183fd62

Please sign in to comment.