Documentation ¶
Overview ¶
Utilities for extracting and formatting data encountered in HTTP requests
Index ¶
- Constants
- Variables
- func AddQ(u *url.URL, key string, value interface{})
- func DecodeResponse(response *http.Response) (io.Reader, error)
- func DelQ(u *url.URL, key string)
- func IsHttpErr(err error) bool
- func JSONDecoder(in io.Reader, out interface{}) error
- func JSONEncoder(in interface{}) (io.Reader, error)
- func ParseFormRequest(req *http.Request, into interface{}) error
- func ParseFormValues(formValues url.Values, into interface{}) error
- func ParseJSON(r io.Reader, into interface{}) error
- func ParseJSONRequest(req *http.Request, into interface{}) error
- func ParseRequest(req *http.Request, into interface{}) error
- func Q(req *http.Request, key string, fallbacks ...string) string
- func QBool(req *http.Request, key string) bool
- func QFloat(req *http.Request, key string, fallbacks ...float64) float64
- func QInt(req *http.Request, key string, fallbacks ...int64) int64
- func QTime(req *http.Request, key string) time.Time
- func RespondJSON(w http.ResponseWriter, data interface{}, status ...int)
- func SetContentTypeParser(contentType string, parser RequestParseFunc)
- func SetQ(u *url.URL, key string, value interface{})
- type Client
- func (self *Client) ClearHeaders()
- func (self *Client) ClearParams()
- func (self *Client) Client(*http.Client) *http.Client
- func (self *Client) Decode(r io.Reader, out interface{}) error
- func (self *Client) Delete(path string, params map[string]interface{}, headers map[string]interface{}) (*http.Response, error)
- func (self *Client) Encode(in interface{}) ([]byte, error)
- func (self *Client) Get(path string, params map[string]interface{}, headers map[string]interface{}) (*http.Response, error)
- func (self *Client) GetWithBody(path string, body interface{}, params map[string]interface{}, ...) (*http.Response, error)
- func (self *Client) Post(path string, body interface{}, params map[string]interface{}, ...) (*http.Response, error)
- func (self *Client) Put(path string, body interface{}, params map[string]interface{}, ...) (*http.Response, error)
- func (self *Client) Request(method Method, path string, body interface{}, params map[string]interface{}, ...) (*http.Response, error)
- func (self *Client) SetClient(client *http.Client)
- func (self *Client) SetDecoder(fn DecoderFunc)
- func (self *Client) SetEncoder(fn EncoderFunc)
- func (self *Client) SetErrorDecoder(fn ErrorDecoderFunc)
- func (self *Client) SetHeader(name string, value interface{})
- func (self *Client) SetParam(name string, value interface{})
- func (self *Client) SetPostRequestHook(fn InterceptResponseFunc)
- func (self *Client) SetPreRequestHook(fn InterceptRequestFunc)
- func (self *Client) URI() *url.URL
- type DecoderFunc
- type EncoderFunc
- type ErrorDecoderFunc
- type InterceptRequestFunc
- type InterceptResponseFunc
- type LogLevel
- type Method
- type RequestLogger
- type RequestParseFunc
- type WritableLogger
Constants ¶
const ( Get Method = `GET` Post = `POST` Put = `PUT` Delete = `DELETE` Head = `HEAD` Options = `OPTIONS` Patch = `PATCH` )
Variables ¶
var FormUnmarshalStructTag = `json`
var Logger = logging.MustGetLogger(`httputil`)
Functions ¶
func DecodeResponse ¶
Takes an http.Response and returns an io.Reader that will return the contents of the Response Body decoded according to the values (if any) of the Content-Encoding response header.
func JSONDecoder ¶
func JSONEncoder ¶
func ParseFormRequest ¶
Parses the form values for a Request and unmarshals into the given value.
func ParseFormValues ¶
Parses a set of values received from an HTML form (usually the value of the http.Request.Form property) and unmarshals into the given value.
func ParseJSONRequest ¶
Parses the Request as JSON and unmarshals into the given value.
func ParseRequest ¶
Autodetect the Content-Type of the given request and unmarshals into the given value.
func RespondJSON ¶
func RespondJSON(w http.ResponseWriter, data interface{}, status ...int)
Marshal the given data as a JSON document and write the output to the given ResponseWriter. If a status is given, that will be used as the HTTP response status. If data is an error, and no status is given, the status will be "500 Internal Server Error"; if data is nil, the status will be "204 No Content". The Content-Type of the response is "application/json".
func SetContentTypeParser ¶
func SetContentTypeParser(contentType string, parser RequestParseFunc)
Sets a parser implementation for the given HTTP content type.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) ClearHeaders ¶
func (self *Client) ClearHeaders()
Remove all implicit HTTP request headers.
func (*Client) ClearParams ¶
func (self *Client) ClearParams()
Remove all implicit querystring parameters.
func (*Client) GetWithBody ¶
func (*Client) Request ¶
func (self *Client) Request( method Method, path string, body interface{}, params map[string]interface{}, headers map[string]interface{}, ) (*http.Response, error)
Perform an HTTP request
func (*Client) SetDecoder ¶
func (self *Client) SetDecoder(fn DecoderFunc)
Specify a decoder that will be used to deserialize data in the response body.
func (*Client) SetEncoder ¶
func (self *Client) SetEncoder(fn EncoderFunc)
Specify an encoder that will be used to serialize data in the request body.
func (*Client) SetErrorDecoder ¶
func (self *Client) SetErrorDecoder(fn ErrorDecoderFunc)
Specify a different decoder used to deserialize non 2xx/3xx HTTP responses.
func (*Client) SetHeader ¶
Add an HTTP request header by name that will be included in every request. If value is nil, the named header will be removed instead.
func (*Client) SetParam ¶
Add a querystring parameter by name that will be included in every request. If value is nil, the parameter will be removed instead.
func (*Client) SetPostRequestHook ¶
func (self *Client) SetPostRequestHook(fn InterceptResponseFunc)
Specify a function tht will be called immediately after a response is received. This function is given the first opportunity to inspect the response, and if it returns a non-nil error, no additional processing (including the Error Decoder function) will be performed.
func (*Client) SetPreRequestHook ¶
func (self *Client) SetPreRequestHook(fn InterceptRequestFunc)
Specify a function that will be called immediately before a request is sent. This function has an opportunity to read and modify the outgoing request, and if it returns a non-nil error, the request will not be sent.
type DecoderFunc ¶
type EncoderFunc ¶
type ErrorDecoderFunc ¶
type InterceptRequestFunc ¶
type InterceptResponseFunc ¶
type RequestLogger ¶
type RequestLogger struct { }
func NewRequestLogger ¶
func NewRequestLogger() *RequestLogger
func (*RequestLogger) ServeHTTP ¶
func (self *RequestLogger) ServeHTTP(rw http.ResponseWriter, req *http.Request, next http.HandlerFunc)
type RequestParseFunc ¶
type WritableLogger ¶
type WritableLogger struct {
// contains filtered or unexported fields
}
func NewWritableLogger ¶
func NewWritableLogger(level LogLevel, prefix ...string) *WritableLogger