From 3e01193d11282838f8f198d1a53e52064f8f56f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Ram=C3=B3n?= Date: Tue, 19 Aug 2025 18:35:20 -0500 Subject: [PATCH 1/2] bin/lint: adds script --- bin/lint.sh | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 bin/lint.sh diff --git a/bin/lint.sh b/bin/lint.sh new file mode 100755 index 0000000..5c54dc7 --- /dev/null +++ b/bin/lint.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +if ! golangci-lint version &> /dev/null +then + echo "golangci-lint not found, installing it" + go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest +fi + +golangci-lint run ./... \ No newline at end of file From 54c67dc28673d68a9236628f84efb14b29f5a8e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20Ram=C3=B3n?= Date: Tue, 19 Aug 2025 20:10:22 -0500 Subject: [PATCH 2/2] {domain,pkg}: adds golangci-lint fixes --- domain/auth/handler.go | 22 +++++++++++++++++----- domain/users/handler.go | 7 ++++++- pkg/ctxutil/ctxutil.go | 6 ++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/domain/auth/handler.go b/domain/auth/handler.go index edb62b0..880a633 100644 --- a/domain/auth/handler.go +++ b/domain/auth/handler.go @@ -3,7 +3,7 @@ package auth import ( "context" "encoding/json" - "io/ioutil" + "io" "log" "net/http" @@ -22,7 +22,11 @@ type handlers struct { func (h *handlers) GetPing() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("ok")) + if _, err := w.Write([]byte("ok")); err != nil { + log.Printf("failed to write to reponse writer: %v", err) + w.WriteHeader(http.StatusInternalServerError) + return + } } } @@ -43,13 +47,17 @@ func (h *handlers) GetCurrentUser() http.HandlerFunc { return } - w.Write([]byte(u.Username)) + if _, err := w.Write([]byte(u.Username)); err != nil { + log.Printf("failed to write to reponse writer: %v", err) + w.WriteHeader(http.StatusInternalServerError) + return + } } } func (h *handlers) PostSignIn() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - b, err := ioutil.ReadAll(r.Body) + b, err := io.ReadAll(r.Body) if err != nil { log.Printf("failed to read request body: %v", err) http.Error(w, "failed to read request body", http.StatusInternalServerError) @@ -74,7 +82,11 @@ func (h *handlers) PostSignIn() http.HandlerFunc { return } - w.Write([]byte(u.Username)) + if _, err := w.Write([]byte(u.Username)); err != nil { + log.Printf("failed to write to reponse writer: %v", err) + w.WriteHeader(http.StatusInternalServerError) + return + } } } diff --git a/domain/users/handler.go b/domain/users/handler.go index a7d359e..e591255 100644 --- a/domain/users/handler.go +++ b/domain/users/handler.go @@ -3,6 +3,7 @@ package users import ( "context" "encoding/json" + "log" "net/http" "github.com/admin-golang/admin/dataloader" @@ -48,7 +49,11 @@ func (h *handlers) GetUsers() http.HandlerFunc { return } - w.Write(resp) + if _, err := w.Write(resp); err != nil { + log.Printf("failed to write to reponse writer: %v", err) + w.WriteHeader(http.StatusInternalServerError) + return + } } } diff --git a/pkg/ctxutil/ctxutil.go b/pkg/ctxutil/ctxutil.go index 5301b73..97b4ff8 100644 --- a/pkg/ctxutil/ctxutil.go +++ b/pkg/ctxutil/ctxutil.go @@ -7,10 +7,12 @@ import ( "strings" ) -const AuthHeaderName = "Authorization" +type AuthHeaderNameType string + +const AuthHeaderName AuthHeaderNameType = "Authorization" func WithAuthHeader(ctx context.Context, header http.Header) context.Context { - return context.WithValue(ctx, AuthHeaderName, header.Get(AuthHeaderName)) + return context.WithValue(ctx, AuthHeaderName, header.Get(string(AuthHeaderName))) } func AuthHeaderValueFromCtx(ctx context.Context) (string, error) {