Documentation
¶
Index ¶
- Constants
- func BuildURL(base string, queryParams map[string]string) (string, error)
- func ContentTypeHTML(w http.ResponseWriter)
- func ContentTypeJSON(w http.ResponseWriter)
- func DefaultClient() *http.Client
- func DetectContentType(name string) (t string)
- func DialContextTimeout(rwtimeout, ctimeout time.Duration) func(ctx context.Context, network, addr string) (net.Conn, error)
- func DialerTimeout(rwtimeout, ctimeout time.Duration) func(network, addr string) (c net.Conn, err error)
- func DumpRequest(fn http.HandlerFunc, body bool, dumper func(error, []byte)) http.HandlerFunc
- func GzipHandlerFn(fn http.HandlerFunc) http.HandlerFunc
- func HTTPGet(url string) ([]byte, error)
- func HasPrefix(s string, p ...string) bool
- func IsRelativeForward(statusCode int, locationHeader string) bool
- func IsTimeoutError(err error) bool
- func NewCookieJar() *cookiejar.Jar
- func ReadBytes(object io.ReadCloser) []byte
- func ReadString(object io.ReadCloser) string
- func RestGet(url string, v interface{}) error
- func RestPost(url string, req interface{}, rsp interface{}) ([]byte, error)
- func ReverseProxy(originalPath, targetHost, targetPath string, timeout time.Duration) *httputil.ReverseProxy
- func ServeImage(imageBytes []byte, fi os.FileInfo) func(w http.ResponseWriter, r *http.Request)
- type DialContextFn
- type Dialer
- type DialerTimeoutBean
- type GzipResponseWriter
- type HTTPReq
- func Delete(url string) (*HTTPReq, error)
- func Get(url string) (*HTTPReq, error)
- func Head(url string) (*HTTPReq, error)
- func MustDelete(url string) *HTTPReq
- func MustGet(url string) *HTTPReq
- func MustHead(url string) *HTTPReq
- func MustPatch(url string) *HTTPReq
- func MustPost(url string) *HTTPReq
- func MustPut(url string) *HTTPReq
- func Patch(url string) (*HTTPReq, error)
- func Post(url string) (*HTTPReq, error)
- func Put(url string) (*HTTPReq, error)
- func (b *HTTPReq) BasicAuth(username, password string) *HTTPReq
- func (b *HTTPReq) Body(data interface{}) *HTTPReq
- func (b *HTTPReq) Bytes() ([]byte, error)
- func (b *HTTPReq) Cookie(cookie *http.Cookie) *HTTPReq
- func (b *HTTPReq) CookieJar(jar *cookiejar.Jar) *HTTPReq
- func (b *HTTPReq) Debug(isdebug bool) *HTTPReq
- func (b *HTTPReq) DumpBody(isdump bool) *HTTPReq
- func (b *HTTPReq) DumpRequest() []byte
- func (b *HTTPReq) DumpRequestString() string
- func (b *HTTPReq) EnableCookie(enable bool) *HTTPReq
- func (b *HTTPReq) Header(key, value string) *HTTPReq
- func (b *HTTPReq) Host(host string) *HTTPReq
- func (b *HTTPReq) JSONBody(obj interface{}) error
- func (b *HTTPReq) Param(key, value string) *HTTPReq
- func (b *HTTPReq) PostFile(formName, filename string) *HTTPReq
- func (b *HTTPReq) ProtocolVersion(vers string) *HTTPReq
- func (b *HTTPReq) Proxy(proxy func(*http.Request) (*url.URL, error)) *HTTPReq
- func (b *HTTPReq) ReadResponseBody(resp *http.Response) ([]byte, error)
- func (b *HTTPReq) Response() (*http.Response, error)
- func (b *HTTPReq) SendOut() (*http.Response, error)
- func (b *HTTPReq) String() (string, error)
- func (b *HTTPReq) TLSClientConfig(config *tls.Config) *HTTPReq
- func (b *HTTPReq) Timeout(connectTimeout, readWriteTimeout time.Duration) *HTTPReq
- func (b *HTTPReq) ToFile(filename string) error
- func (b *HTTPReq) ToJSON(v interface{}) error
- func (b *HTTPReq) ToXML(v interface{}) error
- func (b *HTTPReq) Transport(transport http.RoundTripper) *HTTPReq
- func (b *HTTPReq) UserAgent(useragent string) *HTTPReq
- type ReqOption
- func (s *ReqOption) Delete(url string) (*HTTPReq, error)
- func (s *ReqOption) Get(url string) (*HTTPReq, error)
- func (s *ReqOption) Head(url string) (*HTTPReq, error)
- func (s *ReqOption) MustDelete(url string) *HTTPReq
- func (s *ReqOption) MustGet(url string) *HTTPReq
- func (s *ReqOption) MustHead(url string) *HTTPReq
- func (s *ReqOption) MustPatch(url string) *HTTPReq
- func (s *ReqOption) MustPost(url string) *HTTPReq
- func (s *ReqOption) MustPut(url string) *HTTPReq
- func (s *ReqOption) Patch(url string) (*HTTPReq, error)
- func (s *ReqOption) Post(url string) (*HTTPReq, error)
- func (s *ReqOption) Put(url string) (*HTTPReq, error)
- func (s *ReqOption) Req(rawURL, method string) (*HTTPReq, error)
- func (s *ReqOption) RestGet(url string, v interface{}) error
- func (s *ReqOption) RestPostFn(url string, req interface{}, rsp interface{}, fn func(*HTTPReq)) ([]byte, error)
Constants ¶
const ContentType = "Content-Type"
ContentType ...
Variables ¶
This section is empty.
Functions ¶
func DefaultClient ¶
DefaultClient returns a default client with sensible values for slow 3G connections and above.
func DialContextTimeout ¶
func DialContextTimeout(rwtimeout, ctimeout time.Duration) func(ctx context.Context, network, addr string) (net.Conn, error)
DialContextTimeout implements our own dialer in order to set read and write idle timeouts.
func DialerTimeout ¶
func DialerTimeout(rwtimeout, ctimeout time.Duration) func(network, addr string) (c net.Conn, err error)
DialerTimeout implements our own dialer in order to set read and write idle timeouts.
func DumpRequest ¶
func DumpRequest(fn http.HandlerFunc, body bool, dumper func(error, []byte)) http.HandlerFunc
DumpRequest ...
func IsRelativeForward ¶
IsRelativeForward tells the statusCode is 301/302 and locationHeader is relative
func IsTimeoutError ¶
IsTimeoutError tells that the err is a timeout error.
func NewCookieJar ¶
NewCookieJar creates a cookiejar to store cookies.
func ReverseProxy ¶
func ReverseProxy(originalPath, targetHost, targetPath string, timeout time.Duration) *httputil.ReverseProxy
ReverseProxy reverse proxy originalPath to targetHost with targetPath. And the relative forwarding is rewritten.
func ServeImage ¶
ServeImage ...
Types ¶
type DialContextFn ¶
DialContextFn was defined to make code more readable.
type Dialer ¶
Dialer defines dialer function alias
func TimeoutDialer ¶
TimeoutDialer returns functions of connection dialer with timeout settings for http.Transport Dial field. https://gist.github.com/c4milo/275abc6eccbfd88ad56ca7c77947883a HTTP client with support for read and write timeouts which are missing in Go's standard library.
type DialerTimeoutBean ¶
DialerTimeoutBean ...
func (DialerTimeoutBean) Dial ¶
func (d DialerTimeoutBean) Dial(network, addr string) (c net.Conn, err error)
Dial ...
func (DialerTimeoutBean) DialContext ¶
func (d DialerTimeoutBean) DialContext(ctx context.Context, network, addr string) (c net.Conn, err error)
DialContext ...
type GzipResponseWriter ¶
type GzipResponseWriter struct { io.Writer http.ResponseWriter }
GzipResponseWriter ...
type HTTPReq ¶
type HTTPReq struct {
// contains filtered or unexported fields
}
HTTPReq provides more useful methods for requesting one URL than http.Request.
func MustDelete ¶
MustDelete returns *HTTPReq with DELETE Method.
func (*HTTPReq) BasicAuth ¶
BasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
func (*HTTPReq) DumpRequest ¶
DumpRequest returns the DumpRequest
func (*HTTPReq) DumpRequestString ¶
DumpRequestString returns the DumpRequest string
func (*HTTPReq) EnableCookie ¶
EnableCookie sets enable/disable cookiejar
func (*HTTPReq) Param ¶
Param adds query param in to request. params build query string as ?key1=value1&key2=value2...
func (*HTTPReq) ProtocolVersion ¶
ProtocolVersion set the protocol version for incoming requests. Client requests always use HTTP/1.1.
func (*HTTPReq) Proxy ¶
Proxy set http proxy example:
func(req *http.Request) (*URL.URL, error) { u, _ := URL.ParseRequestURI("http://127.0.0.1:8118") return u, nil }
func (*HTTPReq) ReadResponseBody ¶
ReadResponseBody ...
func (*HTTPReq) TLSClientConfig ¶
TLSClientConfig sets tls connection configurations if visiting https URL.
func (*HTTPReq) ToFile ¶
ToFile saves the body data in response to one file. it calls Response inner.
func (*HTTPReq) ToJSON ¶
ToJSON returns the map that marshals from the body bytes as json in response . it calls Response inner.
func (*HTTPReq) ToXML ¶
ToXML returns the map that marshals from the body bytes as xml in response . it calls Response inner.
type ReqOption ¶
type ReqOption struct { ShowDebug bool EnableCookie bool Gzip bool DumpBody bool UserAgent string ConnectTimeout time.Duration ReadWriteTimeout time.Duration TLSClientConfig *tls.Config CookieJar *cookiejar.Jar Proxy func(*http.Request) (*url.URL, error) Transport http.RoundTripper }
ReqOption ...
func (*ReqOption) MustDelete ¶
MustDelete returns *HTTPReq with DELETE Method.