From 0f7fcaffdb6fa7a39798d12161b6f7501d921a14 Mon Sep 17 00:00:00 2001 From: Renovate Bot Date: Tue, 1 Apr 2025 07:02:30 +0000 Subject: [PATCH 1/2] chore(deps): update golangci/golangci-lint-action action to v7 --- .gitea/workflows/lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml index 77bbbd5..58ea970 100644 --- a/.gitea/workflows/lint.yml +++ b/.gitea/workflows/lint.yml @@ -15,6 +15,6 @@ jobs: with: go-version-file: 'go.mod' - name: golangci-lint - uses: golangci/golangci-lint-action@v6 + uses: golangci/golangci-lint-action@v7 with: version: 'latest' From 5a03c746422b5fc0593854114bfaf417e4c356e5 Mon Sep 17 00:00:00 2001 From: Valentin Brandl Date: Wed, 9 Apr 2025 14:47:05 +0200 Subject: [PATCH 2/2] Fix lints --- handlers/healthcheck.go | 8 ++++---- handlers/index.go | 2 +- handlers/index_test.go | 7 ++++++- handlers/not_found.go | 2 +- handlers/not_found_test.go | 7 ++++++- handlers/template.go | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/handlers/healthcheck.go b/handlers/healthcheck.go index ddca717..b0f2e33 100644 --- a/handlers/healthcheck.go +++ b/handlers/healthcheck.go @@ -15,8 +15,8 @@ const ( ) type Timing struct { - TimeMillis time.Duration `json:"timeMillis"` - Source string `json:"source"` + ExecutionTime time.Duration `json:"executionTime"` + Source string `json:"source"` } type HealthCheckResult struct { @@ -43,8 +43,8 @@ func (app *Application) HealthCheck(w http.ResponseWriter, r *http.Request) { Time: time.Now().UTC(), Timing: []Timing{ { - Source: "HealthCheck", - TimeMillis: time.Since(start), + Source: "HealthCheck", + ExecutionTime: time.Since(start), }, }, Response: HealthCheckResponse{ diff --git a/handlers/index.go b/handlers/index.go index 6e57cc3..42d78dd 100644 --- a/handlers/index.go +++ b/handlers/index.go @@ -13,7 +13,7 @@ func (app *Application) Index(w http.ResponseWriter, r *http.Request) { reqId := RequestID(r) err := indexTemplate.Execute(w, templateData{ - RequestID: reqId, + RequestID: reqId, }) if err != nil { l.Error().Err(err).Msg("error executing template") diff --git a/handlers/index_test.go b/handlers/index_test.go index f912f77..3d2cd62 100644 --- a/handlers/index_test.go +++ b/handlers/index_test.go @@ -1,6 +1,7 @@ package handlers_test import ( + "fmt" "net/http" "net/http/httptest" "testing" @@ -35,7 +36,11 @@ func TestIndex(t *testing.T) { app.Handler().ServeHTTP(w, req) // app.Index(w, req) res := w.Result() - defer res.Body.Close() + defer func() { + if err := res.Body.Close(); err != nil { + fmt.Println("Received error: ", err) + } + }() if res.StatusCode != 200 { t.Errorf("expected status to be 200, got %d", res.StatusCode) diff --git a/handlers/not_found.go b/handlers/not_found.go index fce4408..7f949d6 100644 --- a/handlers/not_found.go +++ b/handlers/not_found.go @@ -14,7 +14,7 @@ func (app *Application) NotFound(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) err := notFoundTemplate.Execute(w, templateData{ - RequestID: reqId, + RequestID: reqId, }) if err != nil { l.Error().Err(err).Msg("error executing template") diff --git a/handlers/not_found_test.go b/handlers/not_found_test.go index 6b49f31..8fb67be 100644 --- a/handlers/not_found_test.go +++ b/handlers/not_found_test.go @@ -1,6 +1,7 @@ package handlers_test import ( + "fmt" "io" "net/http" "net/http/httptest" @@ -16,7 +17,11 @@ func TestNotFound(t *testing.T) { app.Handler().ServeHTTP(w, req) res := w.Result() - defer res.Body.Close() + defer func() { + if err := res.Body.Close(); err != nil { + fmt.Println("Received error: ", err) + } + }() if res.StatusCode != 404 { t.Errorf("expected status to be 404, got %d", res.StatusCode) diff --git a/handlers/template.go b/handlers/template.go index bc7f91a..41e3f9b 100644 --- a/handlers/template.go +++ b/handlers/template.go @@ -10,7 +10,7 @@ var indexTemplate *template.Template var notFoundTemplate *template.Template type templateData struct { - RequestID string + RequestID string } func (app *Application) ParseTemplates() error {