api

package
v0.1.13 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: Apache-2.0, MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// headers
	HeaderEtag            = "ETag"
	HeaderSaveCache       = "X-Save-Cache"
	HeaderLocalCache      = "X-Local-Cache"
	HeaderIfNoneMatch     = "If-None-Match"
	HeaderLastModified    = "Last-Modified"
	HeaderIfModifiedSince = "If-Modified-Since"
	HeaderCacheRevalidate = "X-Cache-Revalidate"
	HeaderContentEncoding = "Content-Encoding"
	HeaderContentType     = "Content-Type"
	HeaderCacheControl    = "Cache-Control"
	HeaderAccept          = "Accept"
	HeaderAuthorization   = "Authorization"
	HeaderUserAgent       = "User-Agent"
	HeaderTimeZone        = "Time-Zone"

	// header values
	CacheHit  = "HIT"
	CacheMiss = "MISS"
)

Variables

This section is empty.

Functions

func CleanupStale

func CleanupStale(cacheDir string) error

func HandleHTTPError

func HandleHTTPError(resp *http.Response) error

HandleHTTPError parses a http.Response into a HTTPError.

func NewHTTPClient

func NewHTTPClient(opts ClientOptions) (*http.Client, error)

Types

type ClientOptions

type ClientOptions struct {
	// AuthToken is the authorization token that will be used
	// to authenticate against API endpoints.
	AuthToken string

	// Headers are the headers that will be sent with every API request.
	// Default headers set are Accept, Content-Type, Time-Zone, and User-Agent.
	// Default headers will be overridden by keys specified in Headers.
	Headers map[string]string

	// Host is the default host that API requests will be sent to.
	Host string

	// Log specifies a writer to write API request logs to.
	Log io.Writer

	// LogColorize enables colorized logging to Log for display in a terminal.
	// Default is no coloring.
	LogColorize bool

	// LogVerboseHTTP enables logging HTTP headers and bodies to Log.
	// Default is only logging request URLs and response statuses.
	// By default fallback to logrus log level.
	LogVerboseHTTP bool

	// SkipDefaultHeaders disables setting of the default headers.
	SkipDefaultHeaders bool

	// Timeout specifies a time limit for each API request.
	// Default is no timeout.
	Timeout time.Duration

	// CacheDir specifies a directory to use for caching GET requests.
	CacheDir string
}

ClientOptions holds available options to configure API clients.

type HTTPError

type HTTPError struct {
	Message    string
	Headers    http.Header
	RequestURL *url.URL
	StatusCode int
}

HTTPError represents an error response from the wpm API.

func (*HTTPError) Error

func (err *HTTPError) Error() string

Allow HTTPError to satisfy error interface.

type RESTClient

type RESTClient struct {
	// contains filtered or unexported fields
}

func DefaultRESTClient

func DefaultRESTClient() (*RESTClient, error)

func NewRESTClient

func NewRESTClient(opts ClientOptions) (*RESTClient, error)

func (*RESTClient) Delete

func (c *RESTClient) Delete(path string, resp any, opts ...RequestOption) error

func (*RESTClient) Do

func (c *RESTClient) Do(method string, path string, body io.Reader, response any, opts ...RequestOption) error

func (*RESTClient) DoWithContext

func (c *RESTClient) DoWithContext(ctx context.Context, method string, path string, body io.Reader, response any, opts ...RequestOption) error

func (*RESTClient) Get

func (c *RESTClient) Get(path string, resp any, opts ...RequestOption) error

func (*RESTClient) Patch

func (c *RESTClient) Patch(path string, body io.Reader, resp any, opts ...RequestOption) error

func (*RESTClient) Post

func (c *RESTClient) Post(path string, body io.Reader, resp any, opts ...RequestOption) error

func (*RESTClient) Put

func (c *RESTClient) Put(path string, body io.Reader, resp any, opts ...RequestOption) error

func (*RESTClient) RequestStream

func (c *RESTClient) RequestStream(ctx context.Context, method string, path string, body io.Reader, opts ...RequestOption) (io.ReadCloser, error)

type RequestOption

type RequestOption func(*http.Request)

func WithHeader

func WithHeader(key, value string) RequestOption

type Transport

type Transport struct {
	Base http.RoundTripper
	// contains filtered or unexported fields
}

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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