Documentation ¶
Overview ¶
client impleemts a generic REST API client which can be used for creating gateway-specific clients
Index ¶
Constants ¶
const ( DefaultTimeout = time.Second * 10 DefaultUserAgent = "github.com/mutablelogic/go-server" PathSeparator = string(os.PathSeparator) ContentTypeJson = "application/json" ContentTypeTextXml = "text/xml" ContentTypeApplicationXml = "application/xml" ContentTypeTextPlain = "text/plain" ContentTypeTextHTML = "text/html" ContentTypeBinary = "application/octet-stream" )
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.
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 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 Payload ¶
func NewGetPayload ¶
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 string) RequestOpt
OptToken adds an authorization header. The header format is "Authorization: Bearer <token>"
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
html implements a generic API client which parses HTML and XML files.
|
html implements a generic API client which parses HTML and XML files. |
ipify implements a generic API client which parses a JSON response.
|
ipify implements a generic API client which parses a JSON response. |