api

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: Apache-2.0, MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleHTTPError

func HandleHTTPError(resp *http.Response) error

func NewCachedClient

func NewCachedClient(httpClient *http.Client, cacheTTL time.Duration) *http.Client

func NewHTTPClient

func NewHTTPClient(opts ...ClientOption) *http.Client

NewHTTPClient initializes an http.Client

Types

type Client

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

Client facilitates making HTTP requests to the Instill API

func NewClient

func NewClient(opts ...ClientOption) *Client

NewClient initializes a Client

func NewClientFromHTTP

func NewClientFromHTTP(httpClient *http.Client) *Client

NewClientFromHTTP takes in an http.Client instance

func (*Client) HTTP

func (c *Client) HTTP() *http.Client

func (Client) REST

func (c Client) REST(hostname string, method string, p string, body io.Reader, data interface{}) error

REST performs a REST request and parses the response.

type ClientOption

type ClientOption = func(http.RoundTripper) http.RoundTripper

ClientOption represents an argument to NewClient

func AddHeader

func AddHeader(name, value string) ClientOption

AddHeader turns a RoundTripper into one that adds a request header

func AddHeaderFunc

func AddHeaderFunc(name string, getValue func(*http.Request) (string, error)) ClientOption

AddHeaderFunc is an AddHeader that gets the string value from a function

func CacheResponse

func CacheResponse(ttl time.Duration, dir string) ClientOption

CacheResponse produces a RoundTripper that caches HTTP responses to disk for a specified amount of time

func ReplaceTripper

func ReplaceTripper(tr http.RoundTripper) ClientOption

ReplaceTripper substitutes the underlying RoundTripper with a custom one

func VerboseLog

func VerboseLog(out io.Writer, logTraffic bool, colorize bool) ClientOption

VerboseLog enables request/response logging within a RoundTripper

type HTTPError

type HTTPError struct {
	StatusCode int
	RequestURL *url.URL
	Message    string
	Errors     []HTTPErrorItem
}

HTTPError is an error returned by a failed API call

func (HTTPError) Error

func (err HTTPError) Error() string

type HTTPErrorItem

type HTTPErrorItem struct {
	Message  string
	Resource string
	Field    string
	Code     string
}

Jump to

Keyboard shortcuts

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