Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BadStatusError ¶
func (*BadStatusError) Error ¶
func (bse *BadStatusError) Error() string
type Client ¶
type Client interface {
Get(ctx context.Context, url string, options ...RequestOption) error
Post(ctx context.Context, url string, options ...RequestOption) error
}
Client provides simpler high level interfaces for http querying.
Unfortunately, go does not currently have good interfaces for doing http requests, requiring a lot of boilerplate and not being very testable (https://github.com/golang/go/issues/23707).
The goal of this client is:
- Simple to use (e.g. a semantic api that handles common errors)
- Simple to test (e.g. a small interface that provides a semantic api)
func NewMockClient ¶
NewMockClient constructs a Client that calls handleRequest instead of actually doing a network request.
func NewTLSClient ¶
NewTLSClient constructs a Client from the given tls.Config.
type Request ¶
type Request struct {
Method string
URL string
Params url.Values
Body interface{}
JSONOutput interface{}
Output io.Writer
Header http.Header
}
Request contains the requested behavior of an HTTP request.
It is an internal object primarly exported for testing with NewMockClient.
type RequestOption ¶
type RequestOption func(*Request)
RequestOption controls the behavior of the HTTP request.
func WithHeader ¶
func WithHeader(k, v string) RequestOption
WithHeader will set the HTTP Header on the request.
func WithJSONBody ¶
func WithJSONBody(b interface{}) RequestOption
WithJSONBody will JSON marshal this object as the HTTP request body.
func WithJSONResponse ¶
func WithJSONResponse(o interface{}) RequestOption
WithJSONResponse will JSON Unmarshal the HTTP response body into this object.
func WithParam ¶
func WithParam(k, v string) RequestOption
WithParam will set the query parameter on the HTTP request url.
func WithResponse ¶
func WithResponse(w io.Writer) RequestOption
WithResponse will write the HTTP response to this writer.