Documentation ¶
Index ¶
- func BuildJSONRequest(method, url string, body interface{}, options ...RequestOption) (*http.Request, error)
- func ReadJSONResponse(resp *http.Response, v interface{}) error
- type ClientOption
- type RequestBuilder
- type RequestDoer
- type RequestDoerFunc
- type RequestOption
- type ResponseError
- type ResponseReader
- type RestClient
- func (r *RestClient) Delete(path string, body, v interface{}, options ...RequestOption) error
- func (r *RestClient) Do(method, path string, body, v interface{}, options ...RequestOption) error
- func (r *RestClient) Get(path string, v interface{}, options ...RequestOption) error
- func (r *RestClient) Patch(path string, body, v interface{}, options ...RequestOption) error
- func (r *RestClient) Post(path string, body, v interface{}, options ...RequestOption) error
- func (r *RestClient) Put(path string, body, v interface{}, options ...RequestOption) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClientOption ¶
type ClientOption func(client *RestClient)
A ClientOption configures a *RestClient.
func Builder ¶
func Builder(builder RequestBuilder) ClientOption
Builder sets the RequestBuilder field of a RestClient.
func Doer ¶
func Doer(doer RequestDoer) ClientOption
Doer sets the RequestDoer field of a RestClient.
func Reader ¶
func Reader(reader ResponseReader) ClientOption
Reader sets the ResponseReader field of a RestClient.
func RequestOptions ¶
func RequestOptions(options ...RequestOption) ClientOption
RequestOptions sets the RequestOptions field of a RestClient.
type RequestBuilder ¶
type RequestBuilder func(method, url string, body interface{}, options ...RequestOption) (*http.Request, error)
A RequestBuilder creates a *http.Request from the given parameters. It is important that each option gets added to the generated request:
req, _ := http.NewRequest(...) for _, option := range options if err := option(req); err != nil { return nil, err } }
type RequestDoer ¶
A RequestDoer sends a *http.Request and returns a *http.Response.
type RequestDoerFunc ¶
A RequestDoerFunc is a function that implements the RequestDoer interface.
type RequestOption ¶
A RequestOption configures a *http.Request.
func BasicAuth ¶
func BasicAuth(user, pass string) RequestOption
BasicAuth adds the specified username and password as basic auth to a request.
func Header ¶
func Header(name, val string) RequestOption
Header adds the specified name and value as a header to a request.
func Headers ¶
func Headers(headers map[string]string) RequestOption
Headers adds the specified names and values as headers to a request
func Query ¶
func Query(query url.Values) RequestOption
Query adds the specified query to a request.
type ResponseError ¶
func NewResponseError ¶
func NewResponseError(resp *http.Response, message string) *ResponseError
func NewResponseErrorf ¶
func NewResponseErrorf(resp *http.Response, format string, tokens ...interface{}) *ResponseError
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
type ResponseReader ¶
A ResponseReader attempts to read a *http.Response into v.
type RestClient ¶
type RestClient struct { Host string RequestBuilder RequestBuilder RequestDoer RequestDoer ResponseReader ResponseReader RequestOptions []RequestOption }
RestClient builds, executes, and reads http requests/responses.
func NewRestClient ¶
func NewRestClient(host string, options ...ClientOption) *RestClient
NewRestClient returns a new RestClient with all of the default fields. Any of the default fields can be changed with the options param.
func (*RestClient) Delete ¶
func (r *RestClient) Delete(path string, body, v interface{}, options ...RequestOption) error
Delete passes its params to RestClient.Do() with the "DELETE" method.
func (*RestClient) Do ¶
func (r *RestClient) Do(method, path string, body, v interface{}, options ...RequestOption) error
Do orchestrates building, performing, and reading http requests and responses.
func (*RestClient) Get ¶
func (r *RestClient) Get(path string, v interface{}, options ...RequestOption) error
Get passes its params to RestClient.Do() with the "GET" method.
func (*RestClient) Patch ¶
func (r *RestClient) Patch(path string, body, v interface{}, options ...RequestOption) error
Patch passes its params to RestClient.Do() with the "PATCH" method.
func (*RestClient) Post ¶
func (r *RestClient) Post(path string, body, v interface{}, options ...RequestOption) error
Post passes its params to RestClient.Do() with the "POST" method.
func (*RestClient) Put ¶
func (r *RestClient) Put(path string, body, v interface{}, options ...RequestOption) error
Put passes its params to RestClient.Do() with the "PUT" method.