Documentation ¶
Index ¶
- Constants
- Variables
- func ConvertTo(data interface{}) url.Values
- func DefaultClient() *http.Client
- func DefaultLog(in bool, method string, url string, seqNo string, no int64, res *Response)
- func DefaultPooledClient() *http.Client
- func DefaultPooledTransport() *http.Transport
- func DefaultTransport() *http.Transport
- func Download(url string, filename string, perm os.FileMode) error
- func URLWithParams(rawUrl string, params map[string]interface{}) (u *url.URL)
- func URLWithPath(rawUrl string, path string, params map[string]interface{}) (u *url.URL)
- func Upload(url string, filename string, headerFunc HeaderFunc) ([]byte, error)
- func UploadV2(url string, form Form, headerFunc HeaderFunc) ([]byte, error)
- type FileForm
- type Form
- type HeaderFunc
- type Http
- func (hp *Http) Do(method string, url string, body io.Reader, headerFunc HeaderFunc, ...) ([]byte, error)
- func (hp *Http) DoBytes(method string, url string, buf []byte, reqOpts ...RequestOption) ([]byte, error)
- func (hp *Http) DoForm(url string, reqOpts ...RequestOption) ([]byte, error)
- func (hp *Http) DoFormWith(rawUrl, query string, reqOpts ...RequestOption) ([]byte, error)
- func (hp *Http) DoFormWithValues(url string, values url.Values, opts ...RequestOption) ([]byte, error)
- func (hp *Http) DoMultiForm(url string, reqOpts ...RequestOption) ([]byte, error)
- func (hp *Http) DoMultiFormWith(rawUrl, query string, reqOpts ...RequestOption) ([]byte, error)
- func (hp *Http) DoMultiFormWithValues(url string, form url.Values, opts ...RequestOption) ([]byte, error)
- func (hp *Http) DoString(method string, url string, buf []byte, reqOpts ...RequestOption) (string, error)
- func (hp *Http) DoV2(method string, url string, body io.Reader, headerFunc HeaderFunc, ...) ([]byte, error)
- func (hp *Http) DoWithHead(method string, url string, buf []byte, headerFunc HeaderFunc, ...) ([]byte, error)
- func (hp *Http) GetResponse() *Response
- func (hp *Http) LogEnabled() bool
- func (hp *Http) SetNewHttpClient(fn NewHttpClientFunc)
- func (hp *Http) WithTimeout(duration time.Duration) *Http
- type LogFunc
- type NewHttpClientFunc
- type ReadForm
- type RequestOption
- func Accept(ct string) RequestOption
- func Body(r io.Reader) RequestOption
- func ContentLength(l int64) RequestOption
- func ContentType(ct string) RequestOption
- func Context(ctx context.Context) RequestOption
- func FormBody(params map[string]interface{}) RequestOption
- func Header(headers map[string]string) RequestOption
- func JsonBody(body interface{}) RequestOption
- func Method(m string) RequestOption
- func Params(params map[string]interface{}) RequestOption
- func Path(path string) RequestOption
- func StringParams(params map[string]string) RequestOption
- func Trace(tracer *httptrace.ClientTrace) RequestOption
- func URL(u *url.URL) RequestOption
- func URLString(rawUrl string) RequestOption
- type Response
- func (res *Response) Error() error
- func (res *Response) FileName() string
- func (res *Response) GetBody() []byte
- func (res *Response) GetContentDisposition() string
- func (res *Response) GetContentLength() int64
- func (res *Response) GetContentType() string
- func (res *Response) IsFile() bool
- func (res *Response) Reset()
- type Url
Constants ¶
const ( KContentType = "Content-Type" KContentDisposition = "Content-Disposition" KContentLength = "Content-Length" )
const ( MimeJSON = "application/json" MimeHTML = "text/html" MimeXML = "application/xml" MimeXML2 = "text/xml" MimePlain = "text/plain" MimeForm = "application/x-www-form-urlencoded" MimeMultipartForm = "multipart/form-data" MimePROTOBUF = "application/x-protobuf" MimeMSGPACK = "application/x-msgpack" MimeMSGPACK2 = "application/msgpack" MimeYAML = "application/x-yaml" MimeJSONUtf8 = "application/json;charset=UTF-8" )
const URLTagName = "url"
Variables ¶
var ( HEAD = Method("HEAD") GET = Method("GET") POST = Method("POST") PUT = Method("PUT") DELETE = Method("DELETE") )
var EnableLog bool = true
var (
FormType = reflect.TypeOf((*Form)(nil)).Elem()
)
Functions ¶
func DefaultClient ¶ added in v1.10.3
DefaultClient returns a new http.Client with similar default values to http.Client, but with a non-shared Transport, idle connections disabled, and keepalives disabled.
func DefaultLog ¶ added in v1.20.81
func DefaultPooledClient ¶ added in v1.10.3
DefaultPooledClient returns a new http.Client with similar default values to http.Client, but with a shared Transport. Do not use this function for transient clients as it can leak file descriptors over time. Only use this for clients that will be re-used for the same host(s).
func DefaultPooledTransport ¶ added in v1.10.3
DefaultPooledTransport returns a new http.Transport with similar default values to http.DefaultTransport. Do not use this for transient transports as it can leak file descriptors over time. Only use this for transports that will be re-used for the same host(s).
func DefaultTransport ¶ added in v1.10.3
DefaultTransport returns a new http.Transport with similar default values to http.DefaultTransport, but with idle connections and keepalives disabled.
func URLWithParams ¶ added in v1.2.10
func URLWithPath ¶ added in v1.2.10
Types ¶
type HeaderFunc ¶ added in v0.5.0
type Http ¶
type Http struct { DisableLog bool SeqNo string TimeOut time.Duration // contains filtered or unexported fields }
func (*Http) Do ¶
func (hp *Http) Do(method string, url string, body io.Reader, headerFunc HeaderFunc, opts ...RequestOption) ([]byte, error)
func (*Http) DoForm ¶ added in v0.2.6
func (hp *Http) DoForm(url string, reqOpts ...RequestOption) ([]byte, error)
DoForm url http://api.xxx.com/ssddd?key=ddd&ddd=sfsf
func (*Http) DoFormWith ¶ added in v0.2.6
func (hp *Http) DoFormWith(rawUrl, query string, reqOpts ...RequestOption) ([]byte, error)
DoFormWith query ssddd=sdsfs&sfssfs=sfsssfs&sfsfsfs&
func (*Http) DoFormWithValues ¶ added in v0.2.6
func (*Http) DoMultiForm ¶ added in v0.2.6
func (hp *Http) DoMultiForm(url string, reqOpts ...RequestOption) ([]byte, error)
func (*Http) DoMultiFormWith ¶ added in v0.2.6
func (hp *Http) DoMultiFormWith(rawUrl, query string, reqOpts ...RequestOption) ([]byte, error)
func (*Http) DoMultiFormWithValues ¶ added in v0.2.6
func (*Http) DoV2 ¶ added in v1.20.81
func (hp *Http) DoV2(method string, url string, body io.Reader, headerFunc HeaderFunc, logger LogFunc, opts ...RequestOption) ([]byte, error)
func (*Http) DoWithHead ¶
func (hp *Http) DoWithHead(method string, url string, buf []byte, headerFunc HeaderFunc, opts ...RequestOption) ([]byte, error)
func (*Http) GetResponse ¶ added in v1.2.10
func (*Http) LogEnabled ¶ added in v1.8.50
func (*Http) SetNewHttpClient ¶ added in v1.10.3
func (hp *Http) SetNewHttpClient(fn NewHttpClientFunc)
type NewHttpClientFunc ¶ added in v1.10.3
type RequestOption ¶ added in v1.2.10
func Accept ¶ added in v1.2.10
func Accept(ct string) RequestOption
func Body ¶ added in v1.2.10
func Body(r io.Reader) RequestOption
func ContentLength ¶ added in v1.2.10
func ContentLength(l int64) RequestOption
func ContentType ¶ added in v1.2.10
func ContentType(ct string) RequestOption
func Context ¶ added in v1.2.10
func Context(ctx context.Context) RequestOption
func FormBody ¶ added in v1.2.10
func FormBody(params map[string]interface{}) RequestOption
func Header ¶ added in v1.2.10
func Header(headers map[string]string) RequestOption
func JsonBody ¶ added in v1.2.10
func JsonBody(body interface{}) RequestOption
func Method ¶ added in v1.2.10
func Method(m string) RequestOption
func Params ¶ added in v1.2.10
func Params(params map[string]interface{}) RequestOption
func Path ¶ added in v1.2.10
func Path(path string) RequestOption
func StringParams ¶ added in v1.2.10
func StringParams(params map[string]string) RequestOption
func Trace ¶ added in v1.2.10
func Trace(tracer *httptrace.ClientTrace) RequestOption
func URL ¶ added in v1.2.10
func URL(u *url.URL) RequestOption
func URLString ¶ added in v1.2.10
func URLString(rawUrl string) RequestOption
type Response ¶ added in v1.2.10
type Response struct { StatusCode int // contains filtered or unexported fields }
Response 请求回应
func (*Response) GetContentDisposition ¶ added in v1.2.10
func (*Response) GetContentLength ¶ added in v1.2.10
func (*Response) GetContentType ¶ added in v1.2.10
type Url ¶ added in v1.1.36
func WithParams ¶ added in v1.2.10
func WithParams(data interface{}) Url