Documentation
¶
Index ¶
- Constants
- func CleanupStale(cacheDir string) error
- func HandleHTTPError(resp *http.Response) error
- func NewHTTPClient(opts ClientOptions) (*http.Client, error)
- type ClientOptions
- type HTTPError
- type RESTClient
- func (c *RESTClient) Delete(path string, resp any, opts ...RequestOption) error
- func (c *RESTClient) Do(method string, path string, body io.Reader, response any, ...) error
- func (c *RESTClient) DoWithContext(ctx context.Context, method string, path string, body io.Reader, response any, ...) error
- func (c *RESTClient) Get(path string, resp any, opts ...RequestOption) error
- func (c *RESTClient) Patch(path string, body io.Reader, resp any, opts ...RequestOption) error
- func (c *RESTClient) Post(path string, body io.Reader, resp any, opts ...RequestOption) error
- func (c *RESTClient) Put(path string, body io.Reader, resp any, opts ...RequestOption) error
- func (c *RESTClient) RequestStream(ctx context.Context, method string, path string, body io.Reader, ...) (io.ReadCloser, error)
- type RequestOption
- type Transport
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 HandleHTTPError ¶
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 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 ¶
func WithHeader ¶
func WithHeader(key, value string) RequestOption
Click to show internal directories.
Click to hide internal directories.