aboutsummaryrefslogtreecommitdiff
path: root/weed/util/request_id/request_id.go
blob: 0550cb58bf15f1cadbb5c7982a15985ebe90f308 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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))
	}
}