Skip to content

Commit 29939ae

Browse files
committed
Generator: API: Add the helper method for setting the X-Opaque-ID header
(cherry picked from commit 3f7b2e8)
1 parent d3ed97f commit 29939ae

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

internal/cmd/generate/commands/gensource/generator.go

+14
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,20 @@ func (f ` + g.Endpoint.MethodWithNamespace() + `) WithHeader(h map[string]string
434434
}
435435
}
436436
}
437+
`)
438+
439+
// Generate methods for the X-Opaque-ID header
440+
g.w(`
441+
// WithOpaqueID adds the X-Opaque-Id header to the HTTP request.
442+
//
443+
func (f ` + g.Endpoint.MethodWithNamespace() + `) WithOpaqueID(s string) func(*` + g.Endpoint.MethodWithNamespace() + `Request) {
444+
return func(r *` + g.Endpoint.MethodWithNamespace() + `Request) {
445+
if r.Header == nil {
446+
r.Header = make(http.Header)
447+
}
448+
r.Header.Set("X-Opaque-Id", s)
449+
}
450+
}
437451
`)
438452
}
439453

0 commit comments

Comments
 (0)