mirror of
https://github.com/chrislusf/seaweedfs
synced 2025-06-29 16:22:46 +02:00
26 lines
485 B
Go
26 lines
485 B
Go
package request_id
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
)
|
|
|
|
const AmzRequestIDHeader = "x-amz-request-id"
|
|
|
|
func Set(ctx context.Context, id string) context.Context {
|
|
return context.WithValue(ctx, AmzRequestIDHeader, id)
|
|
}
|
|
|
|
func Get(ctx context.Context) string {
|
|
if ctx == nil {
|
|
return ""
|
|
}
|
|
id, _ := ctx.Value(AmzRequestIDHeader).(string)
|
|
return id
|
|
}
|
|
|
|
func InjectToRequest(ctx context.Context, req *http.Request) {
|
|
if req != nil {
|
|
req.Header.Set(AmzRequestIDHeader, Get(ctx))
|
|
}
|
|
}
|