Documentation ¶
Index ¶
- Constants
- func SetDefaultSetting(setting ZngueHttpSettings)
- func TimeoutDialer(cTimeout time.Duration, rwTimeout time.Duration) func(net, addr string) (c net.Conn, err error)
- type Filter
- type FilterChain
- type HttpFn
- type HttpMico
- func (m *HttpMico) Bind(i interface{}) error
- func (m *HttpMico) BuildUrl() (string, error)
- func (m *HttpMico) DoRequest() (*ZngueHttp, error)
- func (m *HttpMico) Formaturl(url string) string
- func (m *HttpMico) GetLocal() (string, error)
- func (m *HttpMico) GetResiger() (string, error)
- func (m *HttpMico) Response() (string, error)
- type ZngueHttp
- func (b *ZngueHttp) AddFilters(fcs ...FilterChain) *ZngueHttp
- func (b *ZngueHttp) Body(data interface{}) *ZngueHttp
- func (b *ZngueHttp) Bytes() ([]byte, error)
- func (b *ZngueHttp) Debug(isdebug bool) *ZngueHttp
- func (b *ZngueHttp) DoRequest() (resp *http.Response, err error)
- func (b *ZngueHttp) DoRequestWithCtx(ctx context.Context) (resp *http.Response, err error)
- func (b *ZngueHttp) DumpBody(isdump bool) *ZngueHttp
- func (b *ZngueHttp) DumpRequest() []byte
- func (b *ZngueHttp) GetRequest() *http.Request
- func (b *ZngueHttp) Header(key, value string) *ZngueHttp
- func (b *ZngueHttp) JSONBody(obj interface{}) (*ZngueHttp, error)
- func (b *ZngueHttp) Param(key, value string) *ZngueHttp
- func (b *ZngueHttp) PostFile(formname, filename string) *ZngueHttp
- func (b *ZngueHttp) Response() (*http.Response, error)
- func (b *ZngueHttp) Retries(times int) *ZngueHttp
- func (b *ZngueHttp) RetryDelay(delay time.Duration) *ZngueHttp
- func (b *ZngueHttp) SetBasicAuth(username, password string) *ZngueHttp
- func (b *ZngueHttp) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *ZngueHttp
- func (b *ZngueHttp) SetCookie(cookie *http.Cookie) *ZngueHttp
- func (b *ZngueHttp) SetEnableCookie(enable bool) *ZngueHttp
- func (b *ZngueHttp) SetFilters(fcs ...FilterChain) *ZngueHttp
- func (b *ZngueHttp) SetHost(host string) *ZngueHttp
- func (b *ZngueHttp) SetProtocolVersion(vers string) *ZngueHttp
- func (b *ZngueHttp) SetProxy(proxy func(*http.Request) (*url.URL, error)) *ZngueHttp
- func (b *ZngueHttp) SetTLSClientConfig(config *tls.Config) *ZngueHttp
- func (b *ZngueHttp) SetTimeout(connectTimeout, readWriteTimeout time.Duration) *ZngueHttp
- func (b *ZngueHttp) SetTransport(transport http.RoundTripper) *ZngueHttp
- func (b *ZngueHttp) SetUserAgent(useragent string) *ZngueHttp
- func (b *ZngueHttp) Setting(setting ZngueHttpSettings) *ZngueHttp
- func (b *ZngueHttp) String() (string, error)
- func (b *ZngueHttp) ToFile(filename string) error
- func (b *ZngueHttp) ToJSON(v interface{}) error
- func (b *ZngueHttp) ToXML(v interface{}) error
- func (b *ZngueHttp) ToYAML(v interface{}) error
- func (b *ZngueHttp) XMLBody(obj interface{}) (*ZngueHttp, error)
- func (b *ZngueHttp) YAMLBody(obj interface{}) (*ZngueHttp, error)
- type ZngueHttpSettings
Constants ¶
const GET = "GET"
const POST = "POST"
Variables ¶
This section is empty.
Functions ¶
func SetDefaultSetting ¶
func SetDefaultSetting(setting ZngueHttpSettings)
SetDefaultSetting overwrites default settings
Types ¶
type FilterChain ¶
type HttpMico ¶
type ZngueHttp ¶
type ZngueHttp struct {
// contains filtered or unexported fields
}
ZngueHttp provides more useful methods than http.Request for requesting a url.
func NewZngueRequest ¶
NewZngueRequest returns *ZngueHttp with specific method
func (*ZngueHttp) AddFilters ¶
func (b *ZngueHttp) AddFilters(fcs ...FilterChain) *ZngueHttp
AddFilters adds filter
func (*ZngueHttp) DoRequestWithCtx ¶
func (*ZngueHttp) DumpRequest ¶
DumpRequest returns the DumpRequest
func (*ZngueHttp) GetRequest ¶
GetRequest returns the request object
func (*ZngueHttp) Param ¶
Param adds query param in to request. params build query string as ?key1=value1&key2=value2...
func (*ZngueHttp) Retries ¶
Retries sets Retries times. default is 0 (never retry) -1 retry indefinitely (forever) Other numbers specify the exact retry amount
func (*ZngueHttp) RetryDelay ¶
RetryDelay sets the time to sleep between reconnection attempts
func (*ZngueHttp) SetBasicAuth ¶
SetBasicAuth sets the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
func (*ZngueHttp) SetCheckRedirect ¶
func (b *ZngueHttp) SetCheckRedirect(redirect func(req *http.Request, via []*http.Request) error) *ZngueHttp
SetCheckRedirect specifies the policy for handling redirects.
If CheckRedirect is nil, the Client uses its default policy, which is to stop after 10 consecutive requests.
func (*ZngueHttp) SetEnableCookie ¶
SetEnableCookie sets enable/disable cookiejar
func (*ZngueHttp) SetFilters ¶
func (b *ZngueHttp) SetFilters(fcs ...FilterChain) *ZngueHttp
SetFilters will use the filter as the invocation filters
func (*ZngueHttp) SetProtocolVersion ¶
SetProtocolVersion sets the protocol version for incoming requests. Client requests always use HTTP/1.1.
func (*ZngueHttp) SetProxy ¶
SetProxy sets the HTTP proxy example:
func(req *http.Request) (*url.URL, error) { u, _ := url.ParseRequestURI("http://127.0.0.1:8118") return u, nil }
func (*ZngueHttp) SetTLSClientConfig ¶
SetTLSClientConfig sets TLS connection configuration if visiting HTTPS url.
func (*ZngueHttp) SetTimeout ¶
SetTimeout sets connect time out and read-write time out for ZngueRequest.
func (*ZngueHttp) SetTransport ¶
func (b *ZngueHttp) SetTransport(transport http.RoundTripper) *ZngueHttp
SetTransport sets the transport field
func (*ZngueHttp) SetUserAgent ¶
SetUserAgent sets User-Agent header field
func (*ZngueHttp) Setting ¶
func (b *ZngueHttp) Setting(setting ZngueHttpSettings) *ZngueHttp
Setting changes request settings
func (*ZngueHttp) ToFile ¶
ToFile saves the body data in response to one file. Calls Response inner.
func (*ZngueHttp) ToJSON ¶
ToJSON returns the map that marshals from the body bytes as json in response. Calls Response inner.
func (*ZngueHttp) ToXML ¶
ToXML returns the map that marshals from the body bytes as xml in response . Calls Response inner.
func (*ZngueHttp) ToYAML ¶
ToYAML returns the map that marshals from the body bytes as yaml in response . Calls Response inner.
type ZngueHttpSettings ¶
type ZngueHttpSettings struct { ShowDebug bool UserAgent string ConnectTimeout time.Duration ReadWriteTimeout time.Duration TLSClientConfig *tls.Config Proxy func(*http.Request) (*url.URL, error) Transport http.RoundTripper CheckRedirect func(req *http.Request, via []*http.Request) error EnableCookie bool Gzip bool DumpBody bool Retries int // if set to -1 means will retry forever RetryDelay time.Duration FilterChains []FilterChain }
ZngueHttpSettings is the http.Client setting