Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- type Context
- type FileUpload
- type HandlerChain
- type HandlerFunc
- type Marshal
- type Option
- func EnableCookie(enable bool) Option
- func EnableInsecureTLS(enable bool) Option
- func WithCodec(codec codec.Codec) Option
- func WithPrefixPath(prefixPath string) Option
- func WithProxy(proxy func(*http.Request) (*url.URL, error)) Option
- func WithProxyURL(proxyURL string) Option
- func WithTLSCert(certPEMBlock, keyPEMBlock []byte) Option
- func WithTimeout(timeout time.Duration) Option
- func WithTransport(transport http.RoundTripper) Option
- type Options
- type Req
- func (r *Req) AddCookie(c *http.Cookie) *Req
- func (r *Req) AddFile(fieldName, fileName string, file io.ReadCloser) *Req
- func (r *Req) AddFileContent(fieldName, fileName string, content []byte) *Req
- func (r *Req) AddFiles(patterns ...string) *Req
- func (r *Req) AddFormParam(key string, value interface{}) *Req
- func (r *Req) AddFormParams(params map[string]interface{}) *Req
- func (r *Req) AddHeader(key, value string) *Req
- func (r *Req) AddHeaders(headers map[string]string) *Req
- func (r *Req) AddQueryParam(key string, value interface{}) *Req
- func (r *Req) AddQueryParams(params map[string]interface{}) *Req
- func (r *Req) Build() (*http.Request, error)
- func (r *Req) Context() context.Context
- func (r *Req) Do() *Resp
- func (r *Req) Error() error
- func (r *Req) GetBody() []byte
- func (r *Req) GetClient() Client
- func (r *Req) GetFormParams() url.Values
- func (r *Req) GetHeader() http.Header
- func (r *Req) GetHost() string
- func (r *Req) GetLazyBody() interface{}
- func (r *Req) GetMethod() string
- func (r *Req) GetName() string
- func (r *Req) GetPath() string
- func (r *Req) GetQueryParams() url.Values
- func (r *Req) GetURL() string
- func (r *Req) Use(handlers ...HandlerFunc) *Req
- func (r *Req) WithAccept(contentType string) *Req
- func (r *Req) WithBasicAuth(username, password string) *Req
- func (r *Req) WithBinaryBody(body []byte) *Req
- func (r *Req) WithBody(body interface{}) *Req
- func (r *Req) WithClient(c Client) *Req
- func (r *Req) WithContentType(contentType string) *Req
- func (r *Req) WithContext(ctx context.Context) *Req
- func (r *Req) WithFormParam(key string, value interface{}) *Req
- func (r *Req) WithFormParams(params map[string]interface{}) *Req
- func (r *Req) WithHeader(key, value string) *Req
- func (r *Req) WithJSONBody(body interface{}) *Req
- func (r *Req) WithLazyBody(lazyBody interface{}) *Req
- func (r *Req) WithMethod(method string) *Req
- func (r *Req) WithName(name string) *Req
- func (r *Req) WithOrigin(origin string) *Req
- func (r *Req) WithQueryParam(key string, value interface{}) *Req
- func (r *Req) WithQueryParams(params map[string]interface{}) *Req
- func (r *Req) WithReferer(referer string) *Req
- func (r *Req) WithStreamHeaders() *Req
- func (r *Req) WithURL(rawURL string) *Req
- func (r *Req) WithUserAgent(userAgent string) *Req
- func (r *Req) WithXMLBody(body 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) AsStream() *RespStream
- 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()
- func (r *Resp) ContentLength() int64
- func (r *Resp) ContentType() string
- func (r *Resp) Cost() time.Duration
- func (r *Resp) Dump() string
- func (r *Resp) Error() error
- func (r *Resp) Request() *http.Request
- func (r *Resp) Response() *http.Response
- func (r *Resp) SetError(err error)
- func (r *Resp) StatusCode() int
- func (r *Resp) String() string
- func (r *Resp) Timeout() bool
- type RespStream
- type Unmarshal
Constants ¶
const ( ContentType = "Content-Type" ContentTypeJSON = "application/json; charset=UTF-8" ContentTypeXML = "application/xml; charset=UTF-8" ContentTypeForm = "application/x-www-form-urlencoded; charset=UTF-8" Accept = "Accept" UserAgent = "User-Agent" Referer = "Referer" Origin = "Origin" ContentEncoding = "Content-Encoding" ContentEncodingGzip = "gzip" ContentEncodingDeflate = "deflate" )
content type
const ( StreamStateOpen = "open" StreamStateClosed = "closed" StreamEventMessage = "message" )
Variables ¶
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") )
define errors
var ( ErrStreamClosed = errors.New("stream closed") ErrTooManyEmptyStreamMessages = errors.New("stream has sent too many empty messages") )
var DefaultClient = NewClient()
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Context ¶ added in v0.2.6
func (*Context) Abort ¶ added in v0.2.6
func (c *Context) Abort()
Abort prevents pending handlers from being called. Note that this will not stop the current handler.
func (*Context) AbortWithError ¶ added in v0.2.6
type FileUpload ¶ added in v0.2.6
type FileUpload struct { FieldName string // form field name FileName string // filename in multipart form. File io.ReadCloser // file to upload, required }
FileUpload represents a file to upload
type HandlerChain ¶ added in v0.2.6
type HandlerChain []HandlerFunc
type HandlerFunc ¶ added in v0.2.6
type HandlerFunc func(*Context)
func CompressHandler ¶ added in v0.2.6
func CompressHandler() HandlerFunc
func DumpHandler ¶ added in v0.2.6
func DumpHandler() HandlerFunc
func Recovery ¶ added in v0.2.6
func Recovery() HandlerFunc
type Option ¶ added in v0.2.6
type Option func(options *Options)
func EnableCookie ¶ added in v0.1.16
EnableCookie enable or disable cookie manager
func EnableInsecureTLS ¶ added in v0.1.16
EnableInsecureTLS allows insecure https
func WithPrefixPath ¶ added in v0.2.6
func WithProxyURL ¶ added in v0.1.16
func WithTLSCert ¶ added in v0.1.16
func WithTimeout ¶ added in v0.1.16
func WithTransport ¶ added in v0.1.16
func WithTransport(transport http.RoundTripper) Option
type Options ¶ added in v0.2.6
type Options 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) Codecs codec.Codecs PrefixPath string // prefix path for all request Errors []error }
func NewOptions ¶ added in v0.2.6
func NewOptions() Options
type Req ¶
type Req struct {
// contains filtered or unexported fields
}
Req represents a http request
func (*Req) AddFile ¶ added in v0.2.6
func (r *Req) AddFile(fieldName, fileName string, file io.ReadCloser) *Req
AddFile upload file with custom field name and file name
func (*Req) AddFileContent ¶ added in v0.2.6
AddFileContent upload file with custom field name and file name
func (*Req) AddFormParam ¶ added in v0.2.6
AddFormParam add form parameter
func (*Req) AddFormParams ¶ added in v0.2.6
AddFormParams add multi form parameters
func (*Req) AddHeaders ¶ added in v0.2.6
AddHeaders add multi headers
func (*Req) AddQueryParam ¶ added in v0.2.6
AddQueryParam add query parameter
func (*Req) AddQueryParams ¶ added in v0.2.6
AddQueryParams add multi query parameters
func (*Req) GetBody ¶
GetBody return request body warn: file content can't be got when has upload files.
func (*Req) GetFormParams ¶ added in v0.2.6
GetFormParams return request form params
func (*Req) GetLazyBody ¶ added in v0.2.6
func (r *Req) GetLazyBody() interface{}
GetLazyBody return lazy body
func (*Req) GetQueryParams ¶ added in v0.2.6
GetQueryParams return request query params
func (*Req) Use ¶
func (r *Req) Use(handlers ...HandlerFunc) *Req
Use 仅在当前请求范围生效的中间件,不会改变到DefaultClient
func (*Req) WithAccept ¶ added in v0.2.6
WithAccept is to set Accept header
func (*Req) WithBasicAuth ¶ added in v0.2.6
WithBasicAuth sets the request's Authorization header to use HTTP
func (*Req) WithBinaryBody ¶ added in v0.2.6
WithBinaryBody add binary body
func (*Req) WithContentType ¶ added in v0.2.6
WithContentType is to set Content-Type header
func (*Req) WithContext ¶ added in v0.1.16
WithContext with context
func (*Req) WithFormParam ¶ added in v0.2.6
WithFormParam with form parameter
func (*Req) WithFormParams ¶ added in v0.2.6
WithFormParams with multi form parameters
func (*Req) WithHeader ¶ added in v0.1.16
WithHeader set request method
func (*Req) WithJSONBody ¶ added in v0.1.17
WithJSONBody convert body to json data
func (*Req) WithLazyBody ¶ added in v0.2.6
WithLazyBody 仅将内容原封不动的保存在Req中,交由Handler对lazyBody处理后在转换为实际的Request中的body
func (*Req) WithOrigin ¶ added in v0.2.6
WithOrigin is to set Origin header
func (*Req) WithQueryParam ¶ added in v0.2.6
WithQueryParam with query parameter
func (*Req) WithQueryParams ¶ added in v0.2.6
WithQueryParams with multi query parameters
func (*Req) WithReferer ¶ added in v0.2.6
WithReferer is to set Referer header
func (*Req) WithStreamHeaders ¶ added in v0.3.0
func (*Req) WithUserAgent ¶ added in v0.2.6
WithUserAgent is to set User-Agent header
func (*Req) WithXMLBody ¶ added in v0.1.17
WithXMLBody convert body to xml data
type Resp ¶
type Resp struct {
// contains filtered or unexported fields
}
Resp represents a http response
func (*Resp) AsBytes ¶
AsBytes returns response body as []byte, return error if error happened when reading the response body
func (*Resp) AsJSONStruct ¶
AsJSONStruct convert json response body to struct or map
func (*Resp) AsStream ¶ added in v0.2.7
func (r *Resp) AsStream() *RespStream
AsStream for SSE(Server-Sent Events)
func (*Resp) AsString ¶
AsString returns response body as string, return error if error happened when reading the response body
func (*Resp) AsXMLStruct ¶
AsXMLStruct convert xml response body to struct or map
func (*Resp) ContentLength ¶
ContentLength returns content length
type RespStream ¶ added in v0.3.0
type RespStream struct {
// contains filtered or unexported fields
}
func (*RespStream) Close ¶ added in v0.3.0
func (rs *RespStream) Close()
func (*RespStream) Read ¶ added in v0.3.0
func (rs *RespStream) Read() (eventName string, data string, err error)
func (*RespStream) State ¶ added in v0.3.0
func (rs *RespStream) State() string
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
wechat
Module
|
|
plugins
|
|
breaker/hystrix
Module
|
|
codec/sonic
Module
|
|
encoding/br
Module
|
|
prometheus
Module
|
|
trace
Module
|
|
vo
module
|
|
wrapper
|
|
breaker/hystrix
Module
|
|
prometheus
Module
|
|
trace
Module
|