1
0
Fork 0
mirror of https://github.com/chrislusf/seaweedfs synced 2025-06-29 16:22:46 +02:00
seaweedfs/weed/util/request_id.go
2025-05-28 11:34:02 -07:00

27 lines
516 B
Go

package util
import (
"context"
"net/http"
)
const (
RequestIdHttpHeader = "X-Request-ID"
RequestIDKey = "x-request-id"
)
func GetRequestID(ctx context.Context) string {
if ctx == nil {
return ""
}
id, _ := ctx.Value(RequestIDKey).(string)
return id
}
func WithRequestID(ctx context.Context, id string) context.Context {
return context.WithValue(ctx, RequestIDKey, id)
}
func ReqWithRequestId(req *http.Request, ctx context.Context) {
req.Header.Set(RequestIdHttpHeader, GetRequestID(ctx))
}