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.2 KiB

2 years ago
package tracelog
import (
"context"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
)
2 years ago
func NewCtx(operationID string) context.Context {
2 years ago
c := context.Background()
2 years ago
ctx := context.WithValue(c, constant.OperationID, operationID)
SetOperationID(ctx, operationID)
return ctx
}
func SetOperationID(ctx context.Context, operationID string) {
2 years ago
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)
}
2 years ago
func GetOperationID(ctx context.Context) string {
2 years ago
if ctx.Value(constant.OperationID) != nil {
s, ok := ctx.Value(constant.OperationID).(string)
2 years ago
if ok {
2 years ago
return s
2 years ago
}
2 years ago
}
2 years ago
return ""
2 years ago
}
2 years ago
func GetOpUserID(ctx context.Context) string {
2 years ago
if ctx.Value(constant.OpUserID) != "" {
s, ok := ctx.Value(constant.OpUserID).(string)
if ok {
return s
}
}
return ""
2 years ago
}
2 years ago
func GetConnID(ctx context.Context) string {
if ctx.Value(constant.ConnID) != "" {
s, ok := ctx.Value(constant.ConnID).(string)
if ok {
return s
}
}
return ""
}