Documentation
¶
Overview ¶
Package httputil provides shared HTTP request building utilities
Package httputil provides shared HTTP request building utilities
Index ¶
- Constants
- func ApplyClientIdentityHeaders(h http.Header, clientID, clientUUID, clientVersion string)
- func BuildRequest(ctx context.Context, baseURL, method, endpoint string, query map[string]string, ...) (*http.Request, error)
- func NewHeaderTransport(base http.RoundTripper, headers map[string]string) http.RoundTripper
- func ValidHeaderName(name string) bool
- type QueryBuilder
- func (qb *QueryBuilder) Build() map[string]string
- func (qb *QueryBuilder) Set(key, value string) *QueryBuilder
- func (qb *QueryBuilder) WithData(showAll bool) *QueryBuilder
- func (qb *QueryBuilder) WithExcludeConfigurations(v *bool) *QueryBuilder
- func (qb *QueryBuilder) WithNamedConfigs(useNamedConfigs bool) *QueryBuilder
- func (qb *QueryBuilder) WithOperational() *QueryBuilder
- func (qb *QueryBuilder) WithPopulateInterfaces() *QueryBuilder
Constants ¶
const ( ClientID = "gocmlclient" ContentTypeJSON = "application/json" )
ClientID is the identifier used for the HTTP User-Agent header.
Variables ¶
This section is empty.
Functions ¶
func ApplyClientIdentityHeaders ¶
ApplyClientIdentityHeaders sets gocmlclient identity headers on h. Empty values are ignored.
func BuildRequest ¶
func BuildRequest(ctx context.Context, baseURL, method, endpoint string, query map[string]string, body any) (*http.Request, error)
BuildRequest creates an HTTP request with proper URL construction and body handling
func NewHeaderTransport ¶ added in v0.2.3
func NewHeaderTransport(base http.RoundTripper, headers map[string]string) http.RoundTripper
NewHeaderTransport returns a RoundTripper that applies the configured headers to every outbound request.
func ValidHeaderName ¶ added in v0.2.3
ValidHeaderName reports whether name is a valid HTTP header field name.
Types ¶
type QueryBuilder ¶
type QueryBuilder struct {
// contains filtered or unexported fields
}
QueryBuilder helps build query parameter maps with common patterns
func NewQueryBuilder ¶
func NewQueryBuilder() *QueryBuilder
NewQueryBuilder creates a new query builder
func (*QueryBuilder) Build ¶
func (qb *QueryBuilder) Build() map[string]string
Build returns the built query parameter map
func (*QueryBuilder) Set ¶
func (qb *QueryBuilder) Set(key, value string) *QueryBuilder
Set adds a custom parameter
func (*QueryBuilder) WithData ¶
func (qb *QueryBuilder) WithData(showAll bool) *QueryBuilder
WithData adds data=true when showAll is true
func (*QueryBuilder) WithExcludeConfigurations ¶
func (qb *QueryBuilder) WithExcludeConfigurations(v *bool) *QueryBuilder
WithExcludeConfigurations explicitly sets exclude_configurations.
If v is nil, it does not set any parameter. If v is non-nil, it also sets operational=true to ensure configuration-related fields are available where required.
func (*QueryBuilder) WithNamedConfigs ¶
func (qb *QueryBuilder) WithNamedConfigs(useNamedConfigs bool) *QueryBuilder
WithNamedConfigs adds operational=true and exclude_configurations=false when useNamedConfigs is true
func (*QueryBuilder) WithOperational ¶
func (qb *QueryBuilder) WithOperational() *QueryBuilder
WithOperational adds operational=true
func (*QueryBuilder) WithPopulateInterfaces ¶
func (qb *QueryBuilder) WithPopulateInterfaces() *QueryBuilder
WithPopulateInterfaces adds populate_interfaces=true