Documentation
¶
Index ¶
- func Error(r *http.Request, w http.ResponseWriter, msg string, err error, code int)
- func LoggingMiddleware(rt http.RoundTripper) http.RoundTripper
- func NewClient(opts ClientOpts) *http.Client
- func NewDefaultClient(ctx context.Context) *http.Client
- func NewDefaultClientWithTLS(ctx context.Context, tlsConfig *tls.Config) *http.Client
- func NewTransport(tlsConfig *tls.Config) *http.Transport
- func PayloadLogging(ctx context.Context) bool
- func RequestResponseLoggingMiddleware(rt http.RoundTripper) http.RoundTripper
- func WithPayloadLogging(ctx context.Context, enabled bool) context.Context
- func Write(r *http.Request, w http.ResponseWriter, content []byte)
- func WriteJSON(r *http.Request, w http.ResponseWriter, content any)
- type ClientOpts
- type LoggingRoundTripper
- type Middleware
- type RequestResponseLoggingRoundTripper
- type UserAgentTransport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoggingMiddleware ¶ added in v0.2.6
func LoggingMiddleware(rt http.RoundTripper) http.RoundTripper
LoggingMiddleware wraps a transport with LoggingRoundTripper (method, URL, status).
func NewClient ¶ added in v0.2.6
func NewClient(opts ClientOpts) *http.Client
NewClient returns a configured *http.Client. Middlewares are applied in order, wrapping the base transport.
func NewDefaultClient ¶ added in v0.2.6
NewDefaultClient returns an *http.Client with LoggingRoundTripper, 60s timeout, and default TLS settings. It does NOT carry Grafana bearer tokens — callers must set auth headers per request.
Reads context for configuration:
- PayloadLogging(ctx): when true, adds RequestResponseLoggingMiddleware for full request/response body dumps (includes headers — may expose tokens).
func NewDefaultClientWithTLS ¶ added in v0.2.11
NewDefaultClientWithTLS is like NewDefaultClient but accepts an optional *tls.Config for mTLS or custom CA scenarios. When tlsConfig is nil it behaves identically to NewDefaultClient.
func NewTransport ¶
NewTransport returns an *http.Transport with sensible defaults. If tlsConfig is nil, a default TLS config (TLS 1.2+, verify enabled) is used.
func PayloadLogging ¶ added in v0.2.6
PayloadLogging returns the --log-http-payload flag value from the context.
func RequestResponseLoggingMiddleware ¶ added in v0.2.6
func RequestResponseLoggingMiddleware(rt http.RoundTripper) http.RoundTripper
RequestResponseLoggingMiddleware wraps a transport with RequestResponseLoggingRoundTripper (full request/response body dump via httputil.DumpRequest/DumpResponse).
func WithPayloadLogging ¶ added in v0.2.6
WithPayloadLogging returns a context that carries the --log-http-payload flag value.
Types ¶
type ClientOpts ¶ added in v0.2.6
type ClientOpts struct {
TLSConfig *tls.Config
Timeout time.Duration // default: 60s
Middlewares []Middleware // default: []Middleware{LoggingMiddleware}
}
ClientOpts configures NewClient. See NewDefaultClient for common usage.
type LoggingRoundTripper ¶ added in v0.2.6
type LoggingRoundTripper struct {
Base http.RoundTripper
}
LoggingRoundTripper logs HTTP method, URL, and response status at appropriate levels.
Successful responses (2xx/3xx) and client errors (4xx) are logged at Debug, visible with -vvv. Server errors (5xx) and transport failures are logged at Warn, visible with -v.
type Middleware ¶ added in v0.2.6
type Middleware func(http.RoundTripper) http.RoundTripper
Middleware wraps an http.RoundTripper, e.g. for logging or tracing.
type RequestResponseLoggingRoundTripper ¶ added in v0.2.6
type RequestResponseLoggingRoundTripper struct {
DecoratedTransport http.RoundTripper
}
RequestResponseLoggingRoundTripper logs full HTTP request and response bodies at Debug level via httputil.DumpRequest / httputil.DumpResponse (includes headers — may expose tokens). Enabled when --log-http-payload is set.
type UserAgentTransport ¶ added in v0.2.6
type UserAgentTransport struct {
Base http.RoundTripper
}
UserAgentTransport injects the gcx User-Agent header into every outgoing request.