Documentation ¶
Index ¶
- Variables
- func NewRequest(method, url string, opts ...RequestOption) (*http.Request, error)
- func NewRequestWithContext(ctx context.Context, method, url string, opts ...RequestOption) (*http.Request, error)
- type M
- type RequestOption
- func Auth(name string, password string) RequestOption
- func Body(body io.Reader) RequestOption
- func Cookies(c map[string]string) RequestOption
- func Data(form map[string]string) RequestOption
- func FileContent(filename string) RequestOption
- func Headers(headers map[string]string) RequestOption
- func JSON(v interface{}) RequestOption
- func MultipartForm(form map[string]io.Reader) RequestOption
- func Params(params map[string]string) RequestOption
- type Response
- func Delete(url string, opts ...RequestOption) (*Response, error)
- func Do(req *http.Request) (*Response, error)
- func Get(url string, opts ...RequestOption) (*Response, error)
- func Head(url string, opts ...RequestOption) (*Response, error)
- func NewResponse(resp *http.Response) *Response
- func Options(url string, opts ...RequestOption) (*Response, error)
- func Patch(url string, opts ...RequestOption) (*Response, error)
- func Post(url string, opts ...RequestOption) (*Response, error)
- func Put(url string, opts ...RequestOption) (*Response, error)
- func (r *Response) Close() error
- func (r *Response) Content() ([]byte, error)
- func (r *Response) JSON(v interface{}) error
- func (r *Response) Ok() bool
- func (r *Response) Read(p []byte) (n int, err error)
- func (r *Response) SaveContent(filename string) error
- func (r *Response) SimpleJSON() (*simplejson.Json, error)
- func (r *Response) Text() (string, error)
- func (r *Response) XML(v interface{}) error
- type Session
- func (s *Session) Delete(url string, opts ...RequestOption) (*Response, error)
- func (s *Session) Get(url string, opts ...RequestOption) (*Response, error)
- func (s *Session) Head(url string, opts ...RequestOption) (*Response, error)
- func (s *Session) Options(url string, opts ...RequestOption) (*Response, error)
- func (s *Session) Patch(url string, opts ...RequestOption) (*Response, error)
- func (s *Session) Post(url string, opts ...RequestOption) (*Response, error)
- func (s *Session) Put(url string, opts ...RequestOption) (*Response, error)
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRedirectLimitExceeded will be returned when redirect times over limit. ErrRedirectLimitExceeded = errors.New("requests4go: Request exceeded redirect count limit") )
Functions ¶
func NewRequest ¶ added in v0.1.1
func NewRequest(method, url string, opts ...RequestOption) (*http.Request, error)
NewRequest wrappers the NewRequestWithContext
func NewRequestWithContext ¶ added in v0.1.1
func NewRequestWithContext(ctx context.Context, method, url string, opts ...RequestOption) (*http.Request, error)
NewRequestWithContext builds a new *http.Request with Context and RequestOption
Note: If multiple option will modify the request body, only the last one will take effect. The order of options all will effect final request status.
Types ¶
type RequestOption ¶ added in v0.1.1
A RequestOption is represent a option of request. You can use it to custom request. You can also define your own RequestOption.
func Auth ¶ added in v0.1.1
func Auth(name string, password string) RequestOption
Auth sets basic auth for the request.
func Cookies ¶ added in v0.1.1
func Cookies(c map[string]string) RequestOption
Cookies add the cookie to http.Request.
func Data ¶ added in v0.1.1
func Data(form map[string]string) RequestOption
Data sends form-encoded data.
func FileContent ¶ added in v0.3.0
func FileContent(filename string) RequestOption
FileContent loads file content, and set it be request body.
func Headers ¶ added in v0.1.1
func Headers(headers map[string]string) RequestOption
Headers sets the header for the request. It replaces any existing values. The key is case insensitive.
func JSON ¶ added in v0.1.1
func JSON(v interface{}) RequestOption
JSON encodes the value to json data and set content-type be application/json.
func MultipartForm ¶ added in v0.4.0
func MultipartForm(form map[string]io.Reader) RequestOption
MultipartForm sets a multipart/form-data request body.
func Params ¶ added in v0.1.1
func Params(params map[string]string) RequestOption
Params sets url query parameters for the request. It replaces any existing values.
type Response ¶
Response is a wrapper of the http.Response. It opens up new methods for http.Response.
func Delete ¶
func Delete(url string, opts ...RequestOption) (*Response, error)
Delete sends "DELETE" request.
func Head ¶
func Head(url string, opts ...RequestOption) (*Response, error)
Head sends "HEAD" request.
func Options ¶
func Options(url string, opts ...RequestOption) (*Response, error)
Options sends "OPTIONS" request.
func Patch ¶
func Patch(url string, opts ...RequestOption) (*Response, error)
Patch sends "PATCH" request.
func Post ¶
func Post(url string, opts ...RequestOption) (*Response, error)
Post sends "POST" request.
func (*Response) JSON ¶ added in v0.1.1
JSON reads body of response and unmarshal the response content to v.
func (*Response) SaveContent ¶
SaveContent reads body of response and saves response body to file.
func (*Response) SimpleJSON ¶ added in v0.1.1
SimpleJSON reads body of response and returns simplejson.Json. See the usage of simplejson on https://godoc.org/github.com/bitly/go-simplejson.
type Session ¶
Session allows user use cookies between HTTP requests.
func (*Session) Delete ¶
func (s *Session) Delete(url string, opts ...RequestOption) (*Response, error)
Delete sends a DELETE request, returns Response struct.
func (*Session) Get ¶
func (s *Session) Get(url string, opts ...RequestOption) (*Response, error)
Get sends a GET request, returns Response struct.
func (*Session) Head ¶
func (s *Session) Head(url string, opts ...RequestOption) (*Response, error)
Head sends a HEAD request, returns Response struct.
func (*Session) Options ¶
func (s *Session) Options(url string, opts ...RequestOption) (*Response, error)
Options sends a OPTIONS request, returns Response struct.
func (*Session) Patch ¶
func (s *Session) Patch(url string, opts ...RequestOption) (*Response, error)
Patch sends a PATCH request, returns Response struct.