From 19f5aca4848247cc7eeaf8eccd2af6df8a71c9fd Mon Sep 17 00:00:00 2001 From: Stevan Freeborn Date: Sat, 15 Aug 2026 22:09:59 -0500 Subject: [PATCH] fix: address /home/stevan/go/bin/golangci-lint run ./... issues --- internal/auth/auth.go | 4 +++- internal/auth/auth_test.go | 9 ++++++++- internal/server/handlers_admin.go | 6 +++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/internal/auth/auth.go b/internal/auth/auth.go index f7ed4eb..1545dad 100644 --- a/internal/auth/auth.go +++ b/internal/auth/auth.go @@ -96,6 +96,8 @@ func GetAPIKey(headers http.Header) (string, error) { // token. func MakeRefreshToken() string { bytes := make([]byte, 32) - rand.Read(bytes) + if _, err := rand.Read(bytes); err != nil { + panic(err) + } return hex.EncodeToString(bytes) } diff --git a/internal/auth/auth_test.go b/internal/auth/auth_test.go index 0d5664c..d2b013e 100644 --- a/internal/auth/auth_test.go +++ b/internal/auth/auth_test.go @@ -13,9 +13,16 @@ func TestJwtCreationAndValidation(t *testing.T) { secret := []byte("RTCK2UTcOUkiswdrClC6Z3KmmEq/+QicpD9iRx7J0qY=") jwtString, err := auth.MakeJWT(userId, secret, time.Hour) + if err != nil { + t.Fatalf("failed to create JWT: %v", err) + } + validatedUserId, err := auth.ValidateJWT(jwtString, secret) + if err != nil { + t.Fatalf("failed to validate JWT: %v", err) + } if userId != validatedUserId { - t.Fatalf("received %s expected %s: %v", validatedUserId, userId, err) + t.Fatalf("received %s expected %s", validatedUserId, userId) } } diff --git a/internal/server/handlers_admin.go b/internal/server/handlers_admin.go index 25e42e1..64fc8c0 100644 --- a/internal/server/handlers_admin.go +++ b/internal/server/handlers_admin.go @@ -23,14 +23,14 @@ func (s *Server) HandleIndex(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-Type", "text/html; charset=utf-8") w.WriteHeader(http.StatusOK) - w.Write(s.indexHTML) + _, _ = w.Write(s.indexHTML) } // HandleHealthChecks reports that the service is up. func (s *Server) HandleHealthChecks(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-Type", "text/plain; charset=utf-8") w.WriteHeader(http.StatusOK) - w.Write([]byte("OK")) + _, _ = w.Write([]byte("OK")) } // HandleReset clears the file server hit counter and deletes all users. It is @@ -50,7 +50,7 @@ func (s *Server) HandleReset(w http.ResponseWriter, r *http.Request) { w.Header().Add("Content-Type", "text/plain; charset=utf-8") w.WriteHeader(http.StatusOK) - w.Write([]byte("OK")) + _, _ = w.Write([]byte("OK")) } // HandleMetrics renders the admin page showing how many times the file server