Skip to content
Snippets Groups Projects
Commit bcfc1646 authored by ensiouel's avatar ensiouel
Browse files

refactor

parent fa2242c6
Branches
Tags
No related merge requests found
......@@ -43,16 +43,12 @@ func Object(v any) zapcore.Field {
type callerKey struct{}
// ContextWithCaller добавляет передаваемый аргумент в качестве "вызывающего" в формате GlobalID.
// ContextWithCaller добавляет в контекст передаваемый аргумент в качестве "вызывающего" в формате GlobalID.
// Поддерживает один из типов: string, fmt.Stringer. Если передан аргумент другого типа, в качестве вызывающего
// будет установлен "unknown".
func ContextWithCaller(parent context.Context, caller any) context.Context {
return context.WithValue(parent, callerKey{}, caller)
}
func CallerFromContext(ctx context.Context) zapcore.Field {
func ContextWithCaller(parent context.Context, v any) context.Context {
var caller string
switch value := ctx.Value(callerKey{}).(type) {
switch value := v.(type) {
case string:
caller = value
case fmt.Stringer:
......@@ -60,6 +56,14 @@ func CallerFromContext(ctx context.Context) zapcore.Field {
default:
caller = unknownCaller
}
return context.WithValue(parent, callerKey{}, caller)
}
func CallerFromContext(ctx context.Context) zapcore.Field {
caller, ok := ctx.Value(callerKey{}).(string)
if !ok {
caller = unknownCaller
}
return zap.String("caller", caller)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment