Compare commits

...

2 Commits

Author SHA1 Message Date
132945342f feat: fixed lint errors 2025-11-22 23:52:35 +03:00
80ff5c501d fix: inderect require 2025-11-22 23:32:39 +03:00
5 changed files with 18 additions and 9 deletions

2
go.mod
View File

@@ -20,7 +20,7 @@ require (
github.com/go-openapi/jsonreference v0.20.0 // indirect github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/spec v0.20.6 // indirect github.com/go-openapi/spec v0.20.6 // indirect
github.com/go-openapi/swag v0.19.15 // indirect github.com/go-openapi/swag v0.19.15 // indirect
github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/mux v1.8.1
github.com/josharian/intern v1.0.0 // indirect github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect github.com/mailru/easyjson v0.7.6 // indirect
github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe // indirect github.com/swaggo/files v0.0.0-20220610200504-28940afbdbfe // indirect

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()