feat: implement lab3 load balancing and idempotency

This commit is contained in:
Fedoroff
2026-10-27 20:34:22 +03:00
parent 0ab3a341aa
commit 35ae6f722e
43 changed files with 3045 additions and 42 deletions
+30
View File
@@ -0,0 +1,30 @@
package middleware
import (
"context"
"net/http"
"github.com/google/uuid"
)
type contextKey string
const requestIDKey contextKey = "request_id"
func RequestID(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
requestID := uuid.NewString()
w.Header().Set("X-Request-Id", requestID)
ctx := context.WithValue(r.Context(), requestIDKey, requestID)
r = r.WithContext(ctx)
next.ServeHTTP(w, r)
})
}
func GetRequestID(ctx context.Context) string {
requestID, _ := ctx.Value(requestIDKey).(string)
return requestID
}