Documentation ¶
Overview ¶
client impleemts a generic REST API client which can be used for creating gateway-specific clients
Index ¶
- Constants
- func NewLogTransport(w io.Writer, parent http.RoundTripper, verbose bool) http.RoundTripper
- type Client
- type ClientOpt
- func OptEndpoint(value string) ClientOpt
- func OptHeader(key, value string) ClientOpt
- func OptRateLimit(value float32) ClientOpt
- func OptReqToken(value Token) ClientOpt
- func OptSkipVerify() ClientOpt
- func OptStrict() ClientOpt
- func OptTimeout(value time.Duration) ClientOpt
- func OptTrace(w io.Writer, verbose bool) ClientOpt
- func OptUserAgent(value string) ClientOpt
- type Payload
- type Request
- type RequestOpt
- type Token
- type Unmarshaler
Constants ¶
const ( DefaultTimeout = time.Second * 30 DefaultUserAgent = "github.com/mutablelogic/go-client" PathSeparator = string(os.PathSeparator) ContentTypeJson = "application/json" ContentTypeTextXml = "text/xml" ContentTypeApplicationXml = "application/xml" ContentTypeTextPlain = "text/plain" ContentTypeTextHTML = "text/html" ContentTypeBinary = "application/octet-stream" ContentTypeForm = "multipart/form-data" )
const (
Bearer = "Bearer"
)
Variables ¶
This section is empty.
Functions ¶
func NewLogTransport ¶
func NewLogTransport(w io.Writer, parent http.RoundTripper, verbose bool) http.RoundTripper
NewLogTransport creates middleware into the request/response so you can log the transmission on the wire. Setting verbose to true also displays the body of each response
Types ¶
type Client ¶
func New ¶
New creates a new client with options. OptEndpoint is required as an option to set the endpoint for all requests.
func (*Client) Do ¶
func (client *Client) Do(in Payload, out any, opts ...RequestOpt) error
Do a JSON request with a payload, populate an object with the response and return any errors
type ClientOpt ¶
func OptEndpoint ¶
OptEndpoint sets the endpoint for all requests.
func OptRateLimit ¶
OptRateLimit sets the limit on number of requests per second and the API will sleep when exceeded. For account tokens this is 1 per second
func OptReqToken ¶
OptReqToken sets a request token for all client requests. This can be overridden by the client for individual requests using OptToken.
func OptSkipVerify ¶
func OptSkipVerify() ClientOpt
OptSkipVerify skips TLS certificate domain verification
func OptStrict ¶
func OptStrict() ClientOpt
OptStrict turns on strict content type checking on anything returned from the API
func OptTimeout ¶
OptTimeout sets the timeout on any request. By default, a timeout of 10 seconds is used if OptTimeout is not set
func OptTrace ¶
OptTrace allows you to be the "man in the middle" on any requests so you can see traffic move back and forth. Setting verbose to true also displays the JSON response
func OptUserAgent ¶
OptUserAgent sets the user agent string on each API request It is set to the default if empty string is passed
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func NewJSONRequest ¶
Return a new request with a JSON payload which defaults to GET. The accept parameter is the accepted mime-type of the response.
func NewRequest ¶
Return a new empty request which defaults to GET. The accept parameter is the accepted mime-type of the response.
type RequestOpt ¶
func OptPath ¶
func OptPath(value ...string) RequestOpt
OptPath appends path elements onto a request
func OptQuery ¶
func OptQuery(value url.Values) RequestOpt
OptQuery adds query parameters to a request
func OptToken ¶
func OptToken(value Token) RequestOpt
OptToken adds an authorization header. The header format is "Authorization: Bearer <token>"