Documentation ¶
Index ¶
- func AddErrCode(statusCode int, err error) error
- func ErrorStatusCode(err error) int
- func ExtendServer(s string) string
- func GetCode(c *http.Client, url string) (int, error)
- func GetString(c *http.Client, url string) (string, error)
- func RespError(resp *http.Response) error
- func SetAuthToken(h http.Header, tok string)
- type Client
- func (c *Client) Call(p string, req, resp interface{}) error
- func (c *Client) CallContext(ctx context.Context, p string, req, resp interface{}) error
- func (c *Client) Delete(p string) error
- func (c *Client) Get(p string) (*http.Response, error)
- func (c *Client) GetBytes(p string) ([]byte, error)
- func (c *Client) GetCode(p string) (int, error)
- func (c *Client) GetInto(p string, w io.Writer) (int64, error)
- func (c *Client) GetString(p string) (string, error)
- func (c *Client) JSONCall(p string, req, resp interface{}) error
- func (c *Client) JSONGet(p string, resp interface{}) error
- func (c *Client) JSONPost(p string, req interface{}, w io.Writer) error
- func (c *Client) JSONPut(p string, v interface{}) error
- func (c *Client) Poke(p string) error
- func (c *Client) Post(p string, r io.Reader, w io.Writer) error
- func (c *Client) Put(p string, r io.Reader) error
- func (c *Client) PutBytes(p string, bs []byte) error
- func (c *Client) PutN(p string, r io.Reader, n int64) error
- type StaticToken
- type TokenSource
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddErrCode ¶
AddErrCode adds error code to an error given the http status.
func ErrorStatusCode ¶
ErrorStatusCode returns the status code is it is an HTTP error.
func ExtendServer ¶
ExtendServer extends the server host string with an https:// prefix if it is not a localhost, or an http:// prefix if it is localhost. It only extends the server when the server string can be extends to be a valid URL.
func GetString ¶
GetString gets the string response of the given URL using the given client. It returns an error if the reply code is not 200.
func SetAuthToken ¶
SetAuthToken sets authorization header token.
Types ¶
type Client ¶
type Client struct { Server *url.URL // TokenSource is an optional token source to proivde bearer token. TokenSource TokenSource UserAgent string // Optional User-Agent for each request. Accept string // Optional Accept header. Transport http.RoundTripper }
Client performs client that calls to a remote server with an optional token.
func NewClientMust ¶
NewClientMust creates a client and panics on error.
func NewTokenClient ¶
NewTokenClient creates a new client with a Bearer token.
func NewTokenClientMust ¶
NewTokenClientMust creates a client with auth token and panics on error.
func NewUnixClient ¶
NewUnixClient creates a new client that always goes to a particular unix domain socket.
func (*Client) CallContext ¶
CallContext performs a call with the request as a marshalled JSON object, and the response unmarshalled as a JSON object.
func (*Client) GetInto ¶
GetInto gets the specified path and writes everything from the body to the given writer.
func (*Client) JSONGet ¶
JSONGet gets the content of a path and decodes the response into resp as JSON.
func (*Client) JSONPost ¶
JSONPost posts a JSON object as the request body and writes the body into the given writer.
type StaticToken ¶
type StaticToken struct {
T string
}
StaticToken is a token source that provides a fixed, static token.
func NewStaticToken ¶
func NewStaticToken(tok string) *StaticToken
NewStaticToken creates a new static token provider.
func (*StaticToken) Token ¶
func (s *StaticToken) Token( ctx context.Context, tr http.RoundTripper, ) (string, error)
Token always returns the fixed, static token T.
type TokenSource ¶
TokenSource is an interface that can provides a bearer token for authentication.