Documentation
¶
Overview ¶
Package httpreq an simple http requester
Index ¶
- func AddHeadersToRequest(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 HttpReq
- func (h *HttpReq) BaseURL(baseURL string) *HttpReq
- func (h *HttpReq) BeforeSend(fn func(req *http.Request)) *HttpReq
- func (h *HttpReq) BytesBody(bs []byte) *HttpReq
- func (h *HttpReq) Client(c Doer) *HttpReq
- func (h *HttpReq) ContentType(cType string) *HttpReq
- func (h *HttpReq) JSONBytesBody(bs []byte) *HttpReq
- func (h *HttpReq) Method(method string) *HttpReq
- func (h *HttpReq) MustSend(url string) *http.Response
- func (h *HttpReq) Send(url string) (*http.Response, error)
- func (h *HttpReq) StringBody(s string) *HttpReq
- func (h *HttpReq) WithBody(r io.Reader) *HttpReq
- func (h *HttpReq) WithHeader(key, val string) *HttpReq
- func (h *HttpReq) WithHeaders(kvMap map[string]string) *HttpReq
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddHeadersToRequest ¶
AddHeadersToRequest 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 HttpReq ¶
type HttpReq struct {
// contains filtered or unexported fields
}
HttpReq an simple http requester.
func (*HttpReq) BeforeSend ¶
BeforeSend add callback before send.
func (*HttpReq) ContentType ¶
ContentType with custom content-Type header.
func (*HttpReq) JSONBytesBody ¶ added in v0.4.5
JSONBytesBody with custom bytes body, and set JSON content type
func (*HttpReq) StringBody ¶
StringBody with custom string body
func (*HttpReq) WithHeader ¶
WithHeader with custom header