From 62b480c873880dd4df2ae3541890121a52f80870 Mon Sep 17 00:00:00 2001
From: Piotr Biernat <keedosn@gmail.com>
Date: Thu, 6 Oct 2022 21:50:01 +0200
Subject: [PATCH 1/4] ci/cd debug test

---
 .drone.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.drone.yml b/.drone.yml
index d90244b..6303f46 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -7,7 +7,7 @@ steps:
   image: golang:latest
   commands:
   - go install honnef.co/go/tools/cmd/staticcheck@latest
-  - staticcheck ./src/internal/...
+  - cd src && staticcheck ./...
   volumes:
   - name: gopath
     path: /go

From fc668e633b5739ec984c298a57226895001113ae Mon Sep 17 00:00:00 2001
From: Piotr Biernat <keedosn@gmail.com>
Date: Thu, 6 Oct 2022 21:56:45 +0200
Subject: [PATCH 2/4] go static-check fixes

---
 src/internal/app/handler/handler.go | 8 ++++----
 src/internal/app/server.go          | 6 +++---
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/internal/app/handler/handler.go b/src/internal/app/handler/handler.go
index 1a95ba1..0f76908 100644
--- a/src/internal/app/handler/handler.go
+++ b/src/internal/app/handler/handler.go
@@ -3,7 +3,7 @@ package handler
 import (
 	"bytes"
 	"encoding/json"
-	"io/ioutil"
+	"io"
 	"log"
 	"net/http"
 
@@ -55,9 +55,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 }
 
 func decodeRequestData(r *http.Request, v interface{}) error {
-	buf, _ := ioutil.ReadAll(r.Body)
-	rdr := ioutil.NopCloser(bytes.NewReader(buf))
-	r.Body = ioutil.NopCloser(bytes.NewReader(buf))
+	buf, _ := io.ReadAll(r.Body)
+	rdr := io.NopCloser(bytes.NewReader(buf))
+	r.Body = io.NopCloser(bytes.NewReader(buf))
 
 	json.NewDecoder(rdr).Decode(&v)
 
diff --git a/src/internal/app/server.go b/src/internal/app/server.go
index 794e2bc..2982371 100644
--- a/src/internal/app/server.go
+++ b/src/internal/app/server.go
@@ -3,7 +3,7 @@ package app
 import (
 	"bytes"
 	"encoding/json"
-	"io/ioutil"
+	"io"
 	"log"
 	"net"
 	"net/http"
@@ -63,8 +63,8 @@ func PrepareHeadersMiddleware(next http.Handler) http.Handler {
 
 func ValidateJsonBodyMiddleware(next http.Handler) http.Handler {
 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-		buf, _ := ioutil.ReadAll(r.Body)
-		r.Body = ioutil.NopCloser(bytes.NewReader(buf)) // rollack *Request to original state
+		buf, _ := io.ReadAll(r.Body)
+		r.Body = io.NopCloser(bytes.NewReader(buf)) // rollack *Request to original state
 
 		if len(buf) > 0 && !json.Valid(buf) {
 			w.WriteHeader(http.StatusBadRequest)

From b2fcac3b1d84e727b69eaa3398e5d049ae18c8c4 Mon Sep 17 00:00:00 2001
From: Piotr Biernat <keedosn@gmail.com>
Date: Thu, 6 Oct 2022 21:58:20 +0200
Subject: [PATCH 3/4] ci/cd fixes

---
 .drone.yml | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/.drone.yml b/.drone.yml
index 6303f46..303b906 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -16,7 +16,7 @@ steps:
   image: golang:latest
   commands:
   - go install golang.org/x/lint/golint@latest
-  - golint ./src/internal/...
+  - golint ./src/...
   volumes:
   - name: gopath
     path: /go
@@ -24,7 +24,7 @@ steps:
 - name: analyze
   image: golang:latest
   commands:
-  - go vet ./src/internal/...
+  - cd src && go vet ./...
   volumes:
   - name: gopath
     path: /go

From 99e01ddb42b80ff4e7f730fb52eb95a1ddcb6153 Mon Sep 17 00:00:00 2001
From: Piotr Biernat <keedosn@gmail.com>
Date: Thu, 6 Oct 2022 22:06:00 +0200
Subject: [PATCH 4/4] some code quality fixes

---
 src/cmd/main.go            | 12 ++++++------
 src/internal/app/router.go |  2 +-
 src/internal/app/server.go |  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/cmd/main.go b/src/cmd/main.go
index 0319bd3..049e3ab 100644
--- a/src/cmd/main.go
+++ b/src/cmd/main.go
@@ -14,9 +14,9 @@ import (
 )
 
 const (
-	defHttpIp   = "0.0.0.0"
-	defHttpPort = "8080"
-	defDbUrl    = "postgres://postgres:12345678@127.0.0.1:5432/egommerce"
+	defHTTPIP   = "0.0.0.0"
+	defHTTPPort = "8080"
+	defDbURL    = "postgres://postgres:12345678@127.0.0.1:5432/egommerce"
 )
 
 func main() {
@@ -24,15 +24,15 @@ func main() {
 		app.Panicf("Error loading .env file")
 	}
 
-	httpAddr := net.JoinHostPort(config.GetEnv("SERVER_IP", defHttpIp), defHttpPort)
-	dbConnStr := config.GetEnv("DATABASE_URL", defDbUrl)
+	httpAddr := net.JoinHostPort(config.GetEnv("SERVER_IP", defHTTPIP), defHTTPPort)
+	dbConnStr := config.GetEnv("DATABASE_URL", defDbURL)
 
 	dbc, err := database.Connect(dbConnStr)
 	if err != nil {
 		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)
 
 	go srv.Start()
diff --git a/src/internal/app/router.go b/src/internal/app/router.go
index 4231758..daf9eea 100644
--- a/src/internal/app/router.go
+++ b/src/internal/app/router.go
@@ -13,7 +13,7 @@ func SetupRouter(env *handler.Env) *mux.Router {
 	r.MethodNotAllowedHandler = &handler.MethodNotAllowedHandler{}
 
 	r.Use(PrepareHeadersMiddleware)
-	r.Use(ValidateJsonBodyMiddleware) // probably not needed
+	r.Use(ValidateJSONBodyMiddleware) // probably not needed
 	r.Use(LoggingMiddleware)
 
 	r.Handle("/health", handler.Init(env, handler.HealthCheckHandler)).Methods(http.MethodGet)
diff --git a/src/internal/app/server.go b/src/internal/app/server.go
index 2982371..b7a114f 100644
--- a/src/internal/app/server.go
+++ b/src/internal/app/server.go
@@ -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) {
 		buf, _ := io.ReadAll(r.Body)
 		r.Body = io.NopCloser(bytes.NewReader(buf)) // rollack *Request to original state