Documentation ¶
Index ¶
- Variables
- type Client
- type ClientOption
- func EnableCookie(enable bool) ClientOption
- func EnableInsecureTLS(enable bool) ClientOption
- func WithProxy(proxy func(*http.Request) (*url.URL, error)) ClientOption
- func WithProxyURL(proxyURL string) ClientOption
- func WithTLSCert(certPEMBlock, keyPEMBlock []byte) ClientOption
- func WithTimeout(timeout time.Duration) ClientOption
- func WithTransport(transport http.RoundTripper) ClientOption
- type ClientOptions
- type Req
- func (r *Req) Clone() *Req
- func (r *Req) Do() *Resp
- func (r *Req) GetBody() []byte
- func (r *Req) GetClient() Client
- func (r *Req) GetContext() context.Context
- func (r *Req) Use(wrappers ...wrapper.CallWrapper) *Req
- func (r *Req) WithClient(c Client) *Req
- func (r *Req) WithContext(ctx context.Context) *Req
- func (r *Req) WithFile(fieldName, fileName string, file io.ReadCloser) *Req
- func (r *Req) WithFileBytes(fieldName, fileName string, data []byte) *Req
- func (r *Req) WithHeader(key, value string) *Req
- func (r *Req) WithJSONBody(data interface{}) *Req
- func (r *Req) WithMethod(method string) *Req
- func (r *Req) WithURL(rawURL string) *Req
- func (r *Req) WithXMLBody(data interface{}) *Req
- type Resp
- func (r *Resp) AsBytes() ([]byte, error)
- func (r *Resp) AsFile(dest string) error
- func (r *Resp) AsJSONMap() (map[string]interface{}, error)
- func (r *Resp) AsJSONStruct(v interface{}) error
- func (r *Resp) AsReader() (io.Reader, error)
- func (r *Resp) AsString() (string, error)
- func (r *Resp) AsStruct(v interface{}, unmarshal func([]byte, interface{}) error) error
- func (r *Resp) AsXMLMap() (map[string]interface{}, error)
- func (r *Resp) AsXMLStruct(v interface{}) error
- func (r *Resp) Bytes() []byte
- func (r *Resp) Consume(read bool)
- func (r *Resp) ContentLength() int64
- func (r *Resp) ContentType() string
- func (r *Resp) StatusCode() int
- func (r *Resp) String() string
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNoTransport = errors.New("req: no transport") ErrNoURL = errors.New("req: url not specified") ErrLackParam = errors.New("req: lack param") ErrNoParser = errors.New("resp: no parser") ErrNoFileMatch = errors.New("req: no file match") ErrNotSupportedBody = errors.New("req: not supported body") ErrNoUnmarshal = errors.New("resp: no unmarshal") ErrNoMarshal = errors.New("req: no marshal") ErrParseStruct = errors.New("req: can not parse struct param") ErrBlocked = errors.New("req: circuit breaker blocked") )
define errors
View Source
var (
DefaultClient = NewClient()
)
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface { Init(...ClientOption) error Options() ClientOptions Use(...wrapper.CallWrapper) Client Do(*Req, ...ClientOption) *Resp New() *Req Get(rawURL string) *Req Post(rawURL string) *Req }
func NewClient ¶
func NewClient(opts ...ClientOption) Client
type ClientOption ¶ added in v0.1.16
type ClientOption func(options *ClientOptions)
func EnableCookie ¶ added in v0.1.16
func EnableCookie(enable bool) ClientOption
EnableCookie enable or disable cookie manager
func EnableInsecureTLS ¶ added in v0.1.16
func EnableInsecureTLS(enable bool) ClientOption
EnableInsecureTLS allows insecure https
func WithProxyURL ¶ added in v0.1.16
func WithProxyURL(proxyURL string) ClientOption
func WithTLSCert ¶ added in v0.1.16
func WithTLSCert(certPEMBlock, keyPEMBlock []byte) ClientOption
func WithTimeout ¶ added in v0.1.16
func WithTimeout(timeout time.Duration) ClientOption
func WithTransport ¶ added in v0.1.16
func WithTransport(transport http.RoundTripper) ClientOption
type ClientOptions ¶ added in v0.1.16
type ClientOptions struct { EnableCookie bool Timeout time.Duration DialTimeout time.Duration DialKeepAlive time.Duration MaxIdleConns int IdleConnTimeout time.Duration TLSHandshakeTimeout time.Duration ExpectContinueTimeout time.Duration Transport http.RoundTripper TLSClientConfig *tls.Config Proxy func(*http.Request) (*url.URL, error) Errors []error }
type Req ¶
Req represents a http request
func (*Req) GetContext ¶
GetContext return request context
func (*Req) WithFile ¶ added in v0.1.17
func (r *Req) WithFile(fieldName, fileName string, file io.ReadCloser) *Req
func (*Req) WithFileBytes ¶ added in v0.1.17
func (*Req) WithHeader ¶ added in v0.1.16
func (*Req) WithJSONBody ¶ added in v0.1.17
func (*Req) WithMethod ¶
func (*Req) WithXMLBody ¶ added in v0.1.17
type Resp ¶
type Resp struct { Request *http.Request Response *http.Response Error error Cost time.Duration Timeout bool // contains filtered or unexported fields }
Resp represents a http response
func (*Resp) AsBytes ¶
AsBytes returns response body as []byte, return error if error happend when reading the response body
func (*Resp) AsJSONStruct ¶
AsJSONStruct convert json response body to struct or map
func (*Resp) AsString ¶
AsString returns response body as string, return error if error happend when reading the response body
func (*Resp) AsXMLStruct ¶
AsXMLStruct convert xml response body to struct or map
func (*Resp) ContentLength ¶
ContentLength returns content length
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
wechat
Module
|
|
plugins
|
|
breaker/hystrix
Module
|
|
codec/sonic
Module
|
|
encoding/br
Module
|
|
prometheus
Module
|
|
trace
Module
|
|
vo
module
|
|
breaker/hystrix
Module
|
|
prometheus
Module
|
|
trace
Module
|
Click to show internal directories.
Click to hide internal directories.