Documentation
¶
Overview ¶
Package requests is an elegant and simple HTTP library for golang, built for human beings.
This package mimics the implementation of the classic Python package Requests(https://requests.readthedocs.io/)
Index ¶
- func SetEnvTimeout(timeout int64)
- type Auth
- type AuthType
- type Env
- type Option
- func BasicAuth(username, password string) Option
- func Body(body io.Reader) Option
- func Data(data interface{}) Option
- func Form(form map[string]string) Option
- func FormPairs(kv ...string) Option
- func HeaderPairs(kv ...string) Option
- func Headers(headers map[string]string) Option
- func JSON(obj interface{}) Option
- func ParamPairs(kv ...string) Option
- func Params(params map[string]string) Option
- func Timeout(timeout int64) Option
- type Options
- type Response
- func (r *Response) Close() error
- func (r *Response) Cookies() map[string]*http.Cookie
- func (r *Response) Headers() http.Header
- func (r *Response) JSON(v interface{}) error
- func (r *Response) Method() string
- func (r *Response) Raw() io.ReadCloser
- func (r *Response) StatusCode() int
- func (r *Response) Text() (string, error)
- func (r *Response) URL() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetEnvTimeout ¶ added in v0.0.7
func SetEnvTimeout(timeout int64)
Types ¶
type Option ¶
type Option func(*Options)
Option is the functional option type.
func Data ¶ added in v0.0.4
func Data(data interface{}) Option
Data set raw string into the request body.
func Form ¶
Form encode the given KV into the request body. It also sets the Content-Type as "application/x-www-form-urlencoded".
func FormPairs ¶
FormPairs returns an Form formed by the mapping of key, value ... Pairs panics if len(kv) is odd.
func HeaderPairs ¶
HeaderPairs returns an Headers formed by the mapping of key, value ... Pairs panics if len(kv) is odd.
func JSON ¶
func JSON(obj interface{}) Option
JSON serializes the given struct as JSON into the request body. It also sets the Content-Type as "application/json".
func ParamPairs ¶
ParamPairs returns an Params formed by the mapping of key, value ... Pairs panics if len(kv) is odd.
func Timeout ¶ added in v0.0.7
Timeout specifies a time limit for requests made by this Client. The timeout includes connection time, any redirects, and reading the response body. The timer remains running after Get, Head, Post, or Do return and will interrupt reading of the Response.Body.
A Timeout of zero means no timeout. Default is 60s.
type Options ¶
type Options struct { Headers map[string]string Params map[string]string // body Body io.Reader // different body types Data interface{} Form map[string]string JSON interface{} // auth Auth Auth // timeout seconds Timeout int64 }
Options follow the design of Functional Options(https://github.com/tmrts/go-patterns/blob/master/idiom/functional-options.md)
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is a wrapper of http response.
func (*Response) Raw ¶
func (r *Response) Raw() io.ReadCloser
Raw get the raw socket response from the server.
func (*Response) StatusCode ¶
StatusCode get status code of http response.