Documentation ¶
Index ¶
- type BodyProvider
- type Executor
- type Httpman
- func (h *Httpman) AddHeader(key, value string) *Httpman
- func (h *Httpman) AddQueryParam(key, value string) *Httpman
- func (h *Httpman) AddQueryStruct(queryStruct interface{}) *Httpman
- func (h *Httpman) Client(httpClient *http.Client) *Httpman
- func (h *Httpman) Doer(doer Executor) *Httpman
- func (h *Httpman) NewRequest() *Request
- func (h *Httpman) SetBasicAuth(username, password string) *Httpman
- func (h *Httpman) SetHeader(key, value string) *Httpman
- type Request
- func (r *Request) AddQueryParam(key, value string) *Request
- func (r *Request) AddQueryStruct(queryStruct interface{}) *Request
- func (r *Request) Body(body io.Reader) *Request
- func (r *Request) BodyForm(bodyForm interface{}) *Request
- func (r *Request) BodyJSON(bodyJSON interface{}) *Request
- func (r *Request) BodyProvider(body BodyProvider) *Request
- func (r *Request) Connect(pathURL string) *Request
- func (r *Request) Decode(successV, failureV interface{}) (*http.Response, error)
- func (r *Request) DecodeSuccess(successV interface{}) (*http.Response, error)
- func (r *Request) Delete(pathURL string) *Request
- func (r *Request) Do(req *http.Request, successV, failureV interface{}) (*http.Response, error)
- func (r *Request) Get(pathURL string) *Request
- func (r *Request) Head(pathURL string) *Request
- func (r *Request) Options(pathURL string) *Request
- func (r *Request) Patch(pathURL string) *Request
- func (r *Request) Path(path string) *Request
- func (r *Request) Post(pathURL string) *Request
- func (r *Request) Put(pathURL string) *Request
- func (r *Request) Send() (*http.Request, error)
- func (r *Request) SetHeader(key, value string) *Request
- func (r *Request) Trace(pathURL string) *Request
- type ResponseDecoder
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BodyProvider ¶
type BodyProvider interface { // ContentType returns the Content-Type of the body. ContentType() string // Body returns the io.Reader body. Body() (io.Reader, error) }
BodyProvider provides Body content for http.Request attachment.
type Executor ¶
Executor executes http requests. It is implemented by *http.Client. You can wrap *http.Client with layers of Doers to form a stack of client-side middleware.
type Httpman ¶
type Httpman struct {
// contains filtered or unexported fields
}
Httpman is an HTTP Request builder and sender.
func (*Httpman) AddHeader ¶
AddHeader adds the key, value pair in Headers, appending values for existing keys to the key's values. Header keys are canonicalize.
func (*Httpman) AddQueryParam ¶
AddQueryParam appends query param to the queryStruct. The value pointed to by each queryStruct will be encoded as url query parameters on
func (*Httpman) AddQueryStruct ¶
QueryStruct appends the queryStruct to the queryStructs. The value pointed to by each queryStruct will be encoded as url query parameters on The queryStruct argument should be a pointer to a url tagged struct.
func (*Httpman) Client ¶
Client sets the http Client used to do requests. If a nil client is given, the http.DefaultClient will be used.
func (*Httpman) Doer ¶
Doer sets the custom Doer implementation used to do requests. If a nil client is given, the http.DefaultClient will be used.
func (*Httpman) NewRequest ¶
initiates a new request with defaults
func (*Httpman) SetBasicAuth ¶
SetBasicAuth sets the Authorization header to use HTTP Basic Authentication with the provided username and password. With HTTP Basic Authentication the provided username and password are not encrypted.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request
func (*Request) AddQueryParam ¶
AddQueryParam appends query param to the queryStruct. The value pointed to by each queryStruct will be encoded as url query parameters on
func (*Request) AddQueryStruct ¶
QueryStruct appends the queryStruct to the queryStructs. The value pointed to by each queryStruct will be encoded as url query parameters on The queryStruct argument should be a pointer to a url tagged struct.
func (*Request) Body ¶
Body sets the body. The body value will be set as the Body on new If the provided body is also an io.Closer, the request Body will be closed by http.Client methods.
func (*Request) BodyForm ¶
BodyForm sets the bodyForm. The value pointed to by the bodyForm will be url encoded as the Body on new requests. The bodyForm argument should be a pointer to a url tagged struct.
func (*Request) BodyJSON ¶
BodyJSON sets the bodyJSON. The value pointed to by the bodyJSON will be JSON encoded as the Body on new requests. The bodyJSON argument should be a pointer to a JSON tagged struct.
func (*Request) BodyProvider ¶
func (r *Request) BodyProvider(body BodyProvider) *Request
BodyProvider sets the body provider.
func (*Request) Decode ¶
Receive creates a new HTTP request and returns the response. Success responses (2XX) are JSON decoded into the value pointed to by successV and other responses are JSON decoded into the value pointed to by failureV. If the status code of response is 204(no content) or the Content-Length is 0, decoding is skipped. Any error creating the request, sending it, or decoding the response is returned. Receive is shorthand for calling Request and Do.
func (*Request) DecodeSuccess ¶
ReceiveSuccess creates a new HTTP request and returns the response. Success responses (2XX) are JSON decoded into the value pointed to by successV. Any error creating the request, sending it, or decoding a 2XX response is returned.
func (*Request) Do ¶
Do sends an HTTP request and returns the response. Success responses (2XX) are JSON decoded into the value pointed to by successV and other responses are JSON decoded into the value pointed to by failureV. If the status code of response is 204(no content) or the Content-Length is 0, decoding is skipped. Any error sending the request or decoding the response is returned.
func (*Request) Path ¶
Path extends the rawURL with the given path by resolving the reference to an absolute URL. If parsing errors occur, the baseURL is left unmodified.
type ResponseDecoder ¶
type ResponseDecoder interface { // Decode decodes the response into the value pointed to by v. Decode(resp *http.Response, v interface{}) error }
ResponseDecoder decodes http responses into struct values.