Compare commits

..

5 Commits

Author SHA1 Message Date
04f1519f2c Merge branch 'dev' 2025-11-22 23:53:07 +03:00
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
fe0bd0dddc feat: added license 2025-11-22 22:27:59 +03:00
16a6b5ed94 Merge branch 'dev-ai' 2025-11-22 22:26:39 +03:00
6 changed files with 27 additions and 9 deletions

9
LICENSE.md Normal file
View File

@@ -0,0 +1,9 @@
MIT License
Copyright (c) 2025 Sergey Elpashev
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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