fix: some api bug
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type RequestIdMiddleware struct{}
|
||||
|
||||
func NewRequestMiddleware() *RequestIdMiddleware {
|
||||
return &RequestIdMiddleware{}
|
||||
}
|
||||
|
||||
func (m *RequestIdMiddleware) Handle(next http.HandlerFunc) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
requestId := r.Header.Get("X-Request-Id")
|
||||
if requestId != "" {
|
||||
ctx = context.WithValue(ctx, "request_id", requestId)
|
||||
}
|
||||
next(w, r.WithContext(ctx))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user