Убрал внешнюю зависимость
This commit is contained in:
parent
3f4aec40f5
commit
25160ef847
3 changed files with 6 additions and 10 deletions
5
go.mod
5
go.mod
|
@ -2,7 +2,4 @@ module go.neonxp.ru/middleware
|
||||||
|
|
||||||
go 1.22.1
|
go 1.22.1
|
||||||
|
|
||||||
require (
|
require go.neonxp.ru/objectid v0.0.2
|
||||||
github.com/google/uuid v1.6.0
|
|
||||||
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0
|
|
||||||
)
|
|
||||||
|
|
6
go.sum
6
go.sum
|
@ -1,4 +1,2 @@
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
go.neonxp.ru/objectid v0.0.2 h1:Z/G6zvBxmUq0NTq681oGH8pTbBWwi6VA22YOYludIPs=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
go.neonxp.ru/objectid v0.0.2/go.mod h1:s0dRi//oe1liiKcor1KmWx09WzkD6Wtww8ZaIv+VLBs=
|
||||||
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 h1:985EYyeCOxTpcgOTJpflJUwOeEz0CQOdPt73OzpE9F8=
|
|
||||||
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0/go.mod h1:/lliqkxwWAhPjf5oSOIJup2XcqJaw8RGS6k3TGEc7GI=
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"go.neonxp.ru/objectid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ctxKeyRequestID int
|
type ctxKeyRequestID int
|
||||||
|
@ -15,10 +15,11 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func RequestID(next http.Handler) http.Handler {
|
func RequestID(next http.Handler) http.Handler {
|
||||||
|
objectid.Seed()
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
requestID := r.Header.Get(RequestIDHeader)
|
requestID := r.Header.Get(RequestIDHeader)
|
||||||
if requestID == "" {
|
if requestID == "" {
|
||||||
requestID = uuid.NewString()
|
requestID = objectid.New().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), RequestIDKey, requestID)))
|
next.ServeHTTP(w, r.WithContext(context.WithValue(r.Context(), RequestIDKey, requestID)))
|
||||||
|
|
Loading…
Reference in a new issue