feat: fixed lint errors

This commit is contained in:
2025-11-22 23:52:35 +03:00
parent 80ff5c501d
commit 132945342f
4 changed files with 17 additions and 8 deletions

View File

@@ -33,5 +33,8 @@ func (h *HomeHandler) handleHome(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response) if err := json.NewEncoder(w).Encode(response); err != nil {
// Handle encoding error - we can't write an error response after headers
return
}
} }

View File

@@ -39,5 +39,8 @@ func (h *TimeHandler) handleTime(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json") w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(response) if err := json.NewEncoder(w).Encode(response); err != nil {
// Handle encoding error - we can't write an error response after headers
return
}
} }

View File

@@ -37,10 +37,8 @@ func Initialize(level string, format string, output string) {
}) })
} }
// Set output // Set output (currently not implemented)
if output != "" { // TODO: Implement file output support
//TODO: Use files
}
initialized = true initialized = true
}) })

View File

@@ -8,6 +8,11 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
) )
// requestIDKey is a custom type for context key to avoid collisions
type requestIDKey struct{}
var _ requestIDKey
// RequestIDMiddleware adds a unique request ID to each request // RequestIDMiddleware adds a unique request ID to each request
func RequestIDMiddleware(next http.Handler) http.Handler { func RequestIDMiddleware(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) {
@@ -17,9 +22,9 @@ func RequestIDMiddleware(next http.Handler) http.Handler {
// Set request ID in response header // Set request ID in response header
w.Header().Set("X-Request-ID", requestID) w.Header().Set("X-Request-ID", requestID)
// Add request ID to context // Add request ID to context using custom type
ctx := r.Context() ctx := r.Context()
ctx = context.WithValue(ctx, "request_id", requestID) ctx = context.WithValue(ctx, requestIDKey{}, requestID)
// Log the request ID assignment // Log the request ID assignment
logger := logger.GetLogger() logger := logger.GetLogger()