httputil

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package httputil provides shared HTTP request building utilities

Package httputil provides shared HTTP request building utilities

Index

Constants

View Source
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

func ApplyClientIdentityHeaders(h http.Header, clientID, clientUUID, clientVersion string)

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

func ValidHeaderName(name string) bool

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL