Skip to content

Commit

Permalink
fix(client-wrapper): Update ctx binder nil-safe
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetcanozcan committed Sep 6, 2024
1 parent bd4b573 commit 115da23
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions modules/client/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@ func WithTransport(tr http.RoundTripper) DriverWrapper {
func withCtxBinder() DriverWrapper {
return func(restyClient *resty.Client) *resty.Client {
return restyClient.OnBeforeRequest(func(c *resty.Client, r *resty.Request) error {
context := r.Context()
ctx := r.Context()
h := map[string]string{}
if v := ctxvaluer.CorrelationID.Get(ctx, ""); v != "" {
h[ctxvaluer.CorrelationIDKey] = v
}

h := map[string]string{
ctxvaluer.CorrelationIDKey: context.Value(ctxvaluer.CorrelationIDKey).(string),
ctxvaluer.ExecutorUserKey: context.Value(ctxvaluer.ExecutorUserKey).(string),
ctxvaluer.AgentNameKey: context.Value(ctxvaluer.AgentNameKey).(string),
ctxvaluer.OwnerKey: context.Value(ctxvaluer.OwnerKey).(string),
if v := ctxvaluer.ExecutorUser.Get(ctx, ""); v != "" {
h[ctxvaluer.ExecutorUserKey] = v
}

if v := ctxvaluer.AgentName.Get(ctx, ""); v != "" {
h[ctxvaluer.AgentNameKey] = v
}
r.SetHeaders(h)

if v := ctxvaluer.Owner.Get(ctx, ""); v != "" {
h[ctxvaluer.OwnerKey] = v
}
r.SetHeaders(h)
return nil
})
}
Expand Down

0 comments on commit 115da23

Please sign in to comment.