28 lines
418 B
Go
28 lines
418 B
Go
package requestid
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/bytedance/gopkg/cloud/metainfo"
|
|
)
|
|
|
|
const (
|
|
KLogIDKey = "X_LOGID"
|
|
)
|
|
|
|
func SaveLogID(ctx context.Context, requestID string) context.Context {
|
|
ctx = metainfo.WithValue(ctx, KLogIDKey, requestID)
|
|
return ctx
|
|
}
|
|
|
|
func GetLogID(ctx context.Context) string {
|
|
v, ok := metainfo.GetValue(ctx, KLogIDKey)
|
|
if !ok {
|
|
return "-"
|
|
}
|
|
if v == "" {
|
|
return "-"
|
|
}
|
|
return v
|
|
}
|