some code quality fixes
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Piotr Biernat 2022-10-06 22:06:00 +02:00
parent b2fcac3b1d
commit 99e01ddb42
3 changed files with 8 additions and 8 deletions

View File

@ -14,9 +14,9 @@ import (
) )
const ( const (
defHttpIp = "0.0.0.0" defHTTPIP = "0.0.0.0"
defHttpPort = "8080" defHTTPPort = "8080"
defDbUrl = "postgres://postgres:12345678@127.0.0.1:5432/egommerce" defDbURL = "postgres://postgres:12345678@127.0.0.1:5432/egommerce"
) )
func main() { func main() {
@ -24,15 +24,15 @@ func main() {
app.Panicf("Error loading .env file") app.Panicf("Error loading .env file")
} }
httpAddr := net.JoinHostPort(config.GetEnv("SERVER_IP", defHttpIp), defHttpPort) httpAddr := net.JoinHostPort(config.GetEnv("SERVER_IP", defHTTPIP), defHTTPPort)
dbConnStr := config.GetEnv("DATABASE_URL", defDbUrl) dbConnStr := config.GetEnv("DATABASE_URL", defDbURL)
dbc, err := database.Connect(dbConnStr) dbc, err := database.Connect(dbConnStr)
if err != nil { if err != nil {
app.Panicf("Unable to connect to database: %v\n", err) app.Panicf("Unable to connect to database: %v\n", err)
} }
env := &handler.Env{httpAddr, dbc} env := &handler.Env{Addr: httpAddr, DB: dbc}
srv := app.NewServer(env) srv := app.NewServer(env)
go srv.Start() go srv.Start()

View File

@ -13,7 +13,7 @@ func SetupRouter(env *handler.Env) *mux.Router {
r.MethodNotAllowedHandler = &handler.MethodNotAllowedHandler{} r.MethodNotAllowedHandler = &handler.MethodNotAllowedHandler{}
r.Use(PrepareHeadersMiddleware) r.Use(PrepareHeadersMiddleware)
r.Use(ValidateJsonBodyMiddleware) // probably not needed r.Use(ValidateJSONBodyMiddleware) // probably not needed
r.Use(LoggingMiddleware) r.Use(LoggingMiddleware)
r.Handle("/health", handler.Init(env, handler.HealthCheckHandler)).Methods(http.MethodGet) r.Handle("/health", handler.Init(env, handler.HealthCheckHandler)).Methods(http.MethodGet)

View File

@ -61,7 +61,7 @@ func PrepareHeadersMiddleware(next http.Handler) http.Handler {
}) })
} }
func ValidateJsonBodyMiddleware(next http.Handler) http.Handler { func ValidateJSONBodyMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
buf, _ := io.ReadAll(r.Body) buf, _ := io.ReadAll(r.Body)
r.Body = io.NopCloser(bytes.NewReader(buf)) // rollack *Request to original state r.Body = io.NopCloser(bytes.NewReader(buf)) // rollack *Request to original state