Documentation
¶
Overview ¶
Package httpreq an simple http requester
Index ¶
- func AddHeaders(req *http.Request, header http.Header)
- func BuildBasicAuth(username, password string) string
- func IsClientError(statusCode int) bool
- func IsForbidden(statusCode int) bool
- func IsNotFound(statusCode int) bool
- func IsOK(statusCode int) bool
- func IsRedirect(statusCode int) bool
- func IsServerError(statusCode int) bool
- func IsSuccessful(statusCode int) bool
- func RequestToString(r *http.Request) string
- func ResponseToString(w *http.Response) string
- func ToQueryValues(data interface{}) url.Values
- type Doer
- type DoerFunc
- type Req
- func (h *Req) BaseURL(baseURL string) *Req
- func (h *Req) BeforeSend(fn func(req *http.Request)) *Req
- func (h *Req) BytesBody(bs []byte) *Req
- func (h *Req) Client(c Doer) *Req
- func (h *Req) ContentType(cType string) *Req
- func (h *Req) JSONBytesBody(bs []byte) *Req
- func (h *Req) Method(method string) *Req
- func (h *Req) MustSend(url string) *http.Response
- func (h *Req) Send(url string) (*http.Response, error)
- func (h *Req) StringBody(s string) *Req
- func (h *Req) WithBody(r io.Reader) *Req
- func (h *Req) WithHeader(key, val string) *Req
- func (h *Req) WithHeaders(kvMap map[string]string) *Req
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddHeaders ¶ added in v0.5.12
AddHeaders adds the key, value pairs from the given http.Header to the request. Values for existing keys are appended to the keys values.
func BuildBasicAuth ¶
BuildBasicAuth returns the base64 encoded username:password for basic auth. copied from net/http.
func IsClientError ¶
IsClientError check response is client error (400 - 500)
func IsForbidden ¶
IsForbidden is this response forbidden(403)
func IsRedirect ¶
IsRedirect check response status code is in [301, 302, 303, 307]
func IsServerError ¶
IsServerError check response is server error (500 - 600)
func IsSuccessful ¶
IsSuccessful check response status code is in 200 - 300
func RequestToString ¶ added in v0.4.5
RequestToString convert http Request to string
func ResponseToString ¶ added in v0.4.5
ResponseToString convert http Response to string
func ToQueryValues ¶
ToQueryValues convert string-map to url.Values
Types ¶
type Req ¶ added in v0.5.5
type Req struct {
// contains filtered or unexported fields
}
Req an simple http requester.
func (*Req) BeforeSend ¶ added in v0.5.5
BeforeSend add callback before send.
func (*Req) ContentType ¶ added in v0.5.5
ContentType with custom content-Type header.
func (*Req) JSONBytesBody ¶ added in v0.5.5
JSONBytesBody with custom bytes body, and set JSON content type
func (*Req) StringBody ¶ added in v0.5.5
StringBody with custom string body
func (*Req) WithHeader ¶ added in v0.5.5
WithHeader with custom header