You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/common/tracelog/ctx.go

56 lines
1.1 KiB

package tracelog
import (
"OpenIM/pkg/common/constant"
"context"
)
func NewCtx(operationID string) context.Context {
c := context.Background()
ctx := context.WithValue(c, constant.OperationID, operationID)
SetOperationID(ctx, operationID)
return ctx
}
func SetOperationID(ctx context.Context, operationID string) {
ctx = context.WithValue(ctx, constant.OperationID, operationID)
}
func SetOpUserID(ctx context.Context, opUserID string) {
ctx = context.WithValue(ctx, constant.OpUserID, opUserID)
}
func SetConnID(ctx context.Context, connID string) {
ctx = context.WithValue(ctx, constant.ConnID, connID)
}
func GetOperationID(ctx context.Context) string {
if ctx.Value(constant.OperationID) != nil {
s, ok := ctx.Value(constant.OperationID).(string)
if ok {
return s
}
}
return ""
}
func GetOpUserID(ctx context.Context) string {
if ctx.Value(constant.OpUserID) != "" {
s, ok := ctx.Value(constant.OpUserID).(string)
if ok {
return s
}
}
return ""
}
func GetConnID(ctx context.Context) string {
if ctx.Value(constant.ConnID) != "" {
s, ok := ctx.Value(constant.ConnID).(string)
if ok {
return s
}
}
return ""
}