2023-01-30 11:10:26 +08:00
|
|
|
package tracelog
|
2022-12-30 18:46:02 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2023-03-16 10:46:06 +08:00
|
|
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
|
2022-12-30 18:46:02 +08:00
|
|
|
)
|
|
|
|
|
|
2023-03-14 18:47:40 +08:00
|
|
|
func NewCtx(operationID string) context.Context {
|
2023-03-09 16:36:47 +08:00
|
|
|
c := context.Background()
|
2023-03-14 18:47:40 +08:00
|
|
|
ctx := context.WithValue(c, constant.OperationID, operationID)
|
2023-01-04 11:06:28 +08:00
|
|
|
SetOperationID(ctx, operationID)
|
|
|
|
|
return ctx
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-03 14:08:29 +08:00
|
|
|
func SetOperationID(ctx context.Context, operationID string) {
|
2023-03-14 18:47:40 +08:00
|
|
|
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)
|
2022-12-30 18:46:02 +08:00
|
|
|
}
|
|
|
|
|
|
2023-01-09 16:37:33 +08:00
|
|
|
func GetOperationID(ctx context.Context) string {
|
2023-03-14 18:47:40 +08:00
|
|
|
if ctx.Value(constant.OperationID) != nil {
|
|
|
|
|
s, ok := ctx.Value(constant.OperationID).(string)
|
2023-03-13 12:34:56 +08:00
|
|
|
if ok {
|
2023-03-14 18:47:40 +08:00
|
|
|
return s
|
2023-03-13 12:34:56 +08:00
|
|
|
}
|
2023-03-10 18:37:36 +08:00
|
|
|
}
|
2023-03-14 12:07:25 +08:00
|
|
|
return ""
|
2023-01-09 16:37:33 +08:00
|
|
|
}
|
|
|
|
|
|
2023-01-30 15:28:46 +08:00
|
|
|
func GetOpUserID(ctx context.Context) string {
|
2023-03-14 12:07:25 +08:00
|
|
|
if ctx.Value(constant.OpUserID) != "" {
|
|
|
|
|
s, ok := ctx.Value(constant.OpUserID).(string)
|
|
|
|
|
if ok {
|
|
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ""
|
2023-01-12 16:16:50 +08:00
|
|
|
}
|
|
|
|
|
|
2023-03-14 15:35:58 +08:00
|
|
|
func GetConnID(ctx context.Context) string {
|
|
|
|
|
if ctx.Value(constant.ConnID) != "" {
|
|
|
|
|
s, ok := ctx.Value(constant.ConnID).(string)
|
|
|
|
|
if ok {
|
|
|
|
|
return s
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ""
|
|
|
|
|
}
|