Skip to content

Commit

Permalink
qol
Browse files Browse the repository at this point in the history
  • Loading branch information
jannawro committed Oct 2, 2024
1 parent 766d1c7 commit e068065
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
16 changes: 10 additions & 6 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ import (
)

var (
port string
apiKey string
dbConnStr string
logLevel string
port string
apiKey string
databaseURL string
logLevel string
)

const assetsPath = "/assets/"
Expand All @@ -33,7 +33,7 @@ func main() {
}))
slog.SetDefault(logger)

postgresDatabase, err := postgres.NewDatabase(dbConnStr)
postgresDatabase, err := postgres.NewDatabase(databaseURL)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -93,7 +93,11 @@ func main() {
func parseArguments() {
flag.StringVar(&port, "port", os.Getenv("PORT"), "The port the server should listen on. The default is 8888.")
flag.StringVar(&apiKey, "api-key", os.Getenv("API_KEY"), "API Key for the /api endpoints.")
flag.StringVar(&dbConnStr, "db-connection-string", os.Getenv("DATABASE_URL"), "Connection string for a database.")
flag.StringVar(&databaseURL,
"database-url",
os.Getenv("DATABASE_URL"),
"Database URL. Should be a connection string containing auth credentials and configuration.",
)
flag.StringVar(&logLevel, "log-level", os.Getenv("LOG_LEVEL"), "Set the log level (debug, info, warn, error)")
flag.Parse()
}
Expand Down
7 changes: 7 additions & 0 deletions handlers/rest/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (h *Handler) CreateArticle() http.Handler {
if err != nil {
slog.Error(err.Error(), "requestID", middleware.ReqIDFromCtx(r.Context()))
http.Error(w, internalServerErrorMsg, http.StatusInternalServerError)
return
}
})
}
Expand All @@ -101,6 +102,7 @@ func (h *Handler) GetAllArticles() http.Handler {
if err != nil {
slog.Error(err.Error(), "requestID", middleware.ReqIDFromCtx(r.Context()))
http.Error(w, internalServerErrorMsg, http.StatusInternalServerError)
return
}
})
}
Expand All @@ -126,6 +128,7 @@ func (h *Handler) GetArticleByTitle(slugPathParam string) http.Handler {
if err != nil {
slog.Error(err.Error(), "requestID", middleware.ReqIDFromCtx(r.Context()))
http.Error(w, internalServerErrorMsg, http.StatusInternalServerError)
return
}
})
}
Expand Down Expand Up @@ -158,6 +161,7 @@ func (h *Handler) GetArticleByID(idPathParam string) http.Handler {
if err != nil {
slog.Error(err.Error(), "requestID", middleware.ReqIDFromCtx(r.Context()))
http.Error(w, internalServerErrorMsg, http.StatusInternalServerError)
return
}
})
}
Expand Down Expand Up @@ -187,6 +191,7 @@ func (h *Handler) GetArticlesByTags() http.Handler {
if err != nil {
slog.Error(err.Error(), "requestID", middleware.ReqIDFromCtx(r.Context()))
http.Error(w, internalServerErrorMsg, http.StatusInternalServerError)
return
}
})
}
Expand Down Expand Up @@ -232,6 +237,7 @@ func (h *Handler) UpdateArticleByTitle(slugPathParam string) http.Handler {
if err != nil {
slog.Error(err.Error(), "requestID", middleware.ReqIDFromCtx(r.Context()))
http.Error(w, internalServerErrorMsg, http.StatusInternalServerError)
return
}
})
}
Expand Down Expand Up @@ -271,6 +277,7 @@ func (h *Handler) GetAllTags() http.Handler {
if err != nil {
slog.Error(err.Error(), "requestID", middleware.ReqIDFromCtx(r.Context()))
http.Error(w, internalServerErrorMsg, http.StatusInternalServerError)
return
}
})
}

0 comments on commit e068065

Please sign in to comment.