use gofrs uuid
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/gofrs/uuid/v5"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
@@ -14,7 +14,10 @@ const TraceIdKey contextKey = "trace_id"
|
||||
func ContextMiddleware(logger *slog.Logger) func(http.Handler) http.Handler {
|
||||
return func(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
traceid := uuid.NewString()
|
||||
traceid, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
logger.ErrorContext(r.Context(), err.Error())
|
||||
}
|
||||
ctx := context.WithValue(r.Context(), TraceIdKey, traceid)
|
||||
newReq := r.WithContext(ctx)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user