-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Client grpc mw #12
Client grpc mw #12
Conversation
type FromKeyType string | ||
|
||
// FromKey is the key hold from service name | ||
var FromKey FromKeyType = "x-api-from" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Они внешние из-за какой то идеи? Или нет?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
что бы переиспользовать outside
trace/client_mw.go
Outdated
reqID := GetSimpleReqIDFromContext(ctx) | ||
if reqID != "" { | ||
md, ok := metadata.FromOutgoingContext(ctx) | ||
if ok { | ||
md = metadata.Join(md, metadata.New(map[string]string{string(simpleReqID): reqID})) | ||
ctx = metadata.NewOutgoingContext(ctx, md) | ||
} else { | ||
ctx = metadata.NewOutgoingContext(ctx, metadata.New(map[string]string{string(simpleReqID): reqID})) | ||
} | ||
} else { | ||
ctx, reqID = MustGetSimpleReqIDFromContext(ctx) | ||
md, ok := metadata.FromOutgoingContext(ctx) | ||
if ok { | ||
md = metadata.Join(md, metadata.New(map[string]string{string(simpleReqID): reqID})) | ||
ctx = metadata.NewOutgoingContext(ctx, md) | ||
} | ||
ctx = metadata.NewOutgoingContext(ctx, metadata.New(map[string]string{string(simpleReqID): reqID})) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Меня напрягает эта конструкция. Не очень понятно почему нельзя сразу вызвать MustGetSimpleReqIDFromContext(ctx). И не очень понятно почему при наличии наличии reqID у нас стоит else конструкция, а при генерации её уже нет.
returnFunc := func(ctx context.Context, reqID string) (string, context.Context) { | ||
ctx = context.WithValue(ctx, simpleReqID, reqID) | ||
return reqID, ctx | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Не слишком ли мудрено написано? С функцией GetSimpleReqIDFromMetaData достаточно много общего. Мне кажется можно просто вызвать в этой функции функцию GetSimpleReqIDFromMetaData(), и немного упростить читаемость. Мое мнение что этот паттерн тут прям явно лишний
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
так это совсем разные функции
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
я вижу что функции одинаковые. Просто одна из низ возвращает пустой reqID, в случае если он пустой, а вторая генерирует его. Я про то, что это можно сделать как то так (я мог ошибиться, перепроверь)
func MustGetSimpleReqIDFromMetaData(ctx context.Context) (string, context.Context) {
reqID, ctx := GetSimpleReqIDFromMetaData(ctx)
if reqID == "" {
reqID = GenerateSimpleReqID()
ctx = context.WithValue(ctx, simpleReqID, reqID)
return reqID, ctx
}
return reqID, ctx
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ААА это, ну must это типа сгенерить принудительно)
это паттерн такой
Co-authored-by: Mikhail Barshev <[email protected]>
Add: