httpclient

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package httpclient provides a generic HTTP client base shared by all API client packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyAutoRefresh

func ApplyAutoRefresh[F Fault](ctx context.Context, c *Client[F]) error

ApplyAutoRefresh replaces the HTTP client with one that automatically refreshes oauth2 tokens, using the Client's Config and Token.

func ApplyHTTPClient

func ApplyHTTPClient[F Fault](c *Client[F], client *http.Client) error

ApplyHTTPClient replaces the HTTP client entirely.

func ApplyHTTPTracing

func ApplyHTTPTracing[F Fault](c *Client[F], debug bool) error

ApplyHTTPTracing wraps the HTTP client's transport with verbose logging when debug is true.

func ApplyRateLimiter

func ApplyRateLimiter[F Fault](c *Client[F], r *rate.Limiter) error

ApplyRateLimiter wraps the HTTP client's transport with a rate limiter.

func ApplyTransport

func ApplyTransport[F Fault](c *Client[F], t http.RoundTripper) error

ApplyTransport sets the HTTP client's transport.

Types

type Client

type Client[F Fault] struct {
	HTTP   *http.Client
	Token  *oauth2.Token
	Config oauth2.Config
	// contains filtered or unexported fields
}

Client holds the common HTTP state shared by all API clients. F is the package-specific error type used when an HTTP response indicates failure.

func New

func New[F Fault](newFault func() F) *Client[F]

New returns a Client[F] with a default http.Client and oauth2.Token.

func (*Client[F]) Do

func (c *Client[F]) Do(req *http.Request, v any) error

Do executes the HTTP request and populates v with the decoded response body. If the response status indicates an error, a new F is decoded and returned.

type Fault

type Fault interface {
	error
	SetDefaults(code int, message string)
}

Fault is the interface constraint for HTTP API error types. Implementations are decoded from JSON error responses; SetDefaults populates the Code and Message fields from the HTTP status when the body does not supply them.

Jump to

Keyboard shortcuts

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