Documentation ¶
Index ¶
- Variables
- type FileUpload
- type HOpt
- type HTTPClient
- func (api *HTTPClient) Delete(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func (api *HTTPClient) Get(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func (api *HTTPClient) Head(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func (api *HTTPClient) Options(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func (api *HTTPClient) Patch(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func (api *HTTPClient) Post(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func (api *HTTPClient) Put(url string, rOpts ...ROpt) (*HTTPResponse, error)
- type HTTPRequest
- type HTTPResponse
- func Delete(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func Get(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func Head(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func NewResponse(response *resty.Response) *HTTPResponse
- func Options(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func Patch(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func Post(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func Put(url string, rOpts ...ROpt) (*HTTPResponse, error)
- func (resp *HTTPResponse) ContentType() string
- func (resp *HTTPResponse) Cookie(name string) (*http.Cookie, error)
- func (resp *HTTPResponse) Cookies() []*http.Cookie
- func (resp *HTTPResponse) FileName() (string, error)
- func (resp *HTTPResponse) FileNameWithCustom(nameField string) (string, error)
- func (resp *HTTPResponse) Header(name string) string
- func (resp *HTTPResponse) Json(dst interface{}) error
- func (resp *HTTPResponse) OK() bool
- func (resp *HTTPResponse) StatusCode() int
- func (resp *HTTPResponse) Text() string
- type ROpt
- func RWithContext(ctx context.Context) ROpt
- func RWithCookie(cookie []*http.Cookie) ROpt
- func RWithFile(file *FileUpload) ROpt
- func RWithFiles(files []*FileUpload) ROpt
- func RWithForm(form map[string]string) ROpt
- func RWithHeader(header map[string]string) ROpt
- func RWithJson(body []byte) ROpt
- func RWithParams(params map[string]string) ROpt
- func RWithRetryWaitTime(t time.Duration) ROpt
- func RWithTimeout(timeout time.Duration) ROpt
- func RWithTries(retries int) ROpt
- func RWithUserAgent(userAgent string) ROpt
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNoDisposition = errors.New("not found content disposition header") ErrNotFoundDstField = errors.New("not found dst field") )
View Source
var RequestError = errors.New("RequestError")
Functions ¶
This section is empty.
Types ¶
type FileUpload ¶
type FileUpload struct { FileName string //文件名 FileContents io.ReadCloser //文件流 FieldName string //上传文件表单 文件字段 FileMime string //文件类型, 默认是application/octet-stream }
type HOpt ¶ added in v1.2.0
type HOpt func(client *HTTPClient)
func HWithLogger ¶ added in v1.4.13
func HWithMaxRetry ¶ added in v1.2.1
func HWithRetryWaitTime ¶ added in v1.4.13
func HWithTimeout ¶ added in v1.4.13
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
func NewHTTPClient ¶
func NewHTTPClient(hOPts ...HOpt) *HTTPClient
func (*HTTPClient) Delete ¶
func (api *HTTPClient) Delete(url string, rOpts ...ROpt) (*HTTPResponse, error)
Delete DELETE请求方法.
func (*HTTPClient) Get ¶
func (api *HTTPClient) Get(url string, rOpts ...ROpt) (*HTTPResponse, error)
Get GET请求方法.
func (*HTTPClient) Head ¶
func (api *HTTPClient) Head(url string, rOpts ...ROpt) (*HTTPResponse, error)
Head HEAD请求方法.
func (*HTTPClient) Options ¶
func (api *HTTPClient) Options(url string, rOpts ...ROpt) (*HTTPResponse, error)
Options OPTIONS请求方法.
func (*HTTPClient) Patch ¶
func (api *HTTPClient) Patch(url string, rOpts ...ROpt) (*HTTPResponse, error)
Patch PATCH请求方法.
func (*HTTPClient) Post ¶
func (api *HTTPClient) Post(url string, rOpts ...ROpt) (*HTTPResponse, error)
Post Post请求方法.
func (*HTTPClient) Put ¶
func (api *HTTPClient) Put(url string, rOpts ...ROpt) (*HTTPResponse, error)
Put PUT请求方法.
type HTTPRequest ¶
type HTTPRequest struct { Header map[string]string // 请求头 Params map[string]string // 查询字符串 Form map[string]string // 表单参数 Json []byte // json请求体 Cookie []*http.Cookie // Cookie UserAgent string // UserAgent Files []*FileUpload // 文件 Context context.Context // 上下文 Timeout time.Duration // 超市时间 Retries int // 重试次数 RetryWaitTime time.Duration // 重试等待时间 }
func NewRequest ¶
func NewRequest(args ...ROpt) *HTTPRequest
type HTTPResponse ¶
type HTTPResponse struct {
// contains filtered or unexported fields
}
func NewResponse ¶
func NewResponse(response *resty.Response) *HTTPResponse
func (*HTTPResponse) ContentType ¶
func (resp *HTTPResponse) ContentType() string
ContentType 获取Content-Type.
func (*HTTPResponse) Cookie ¶
func (resp *HTTPResponse) Cookie(name string) (*http.Cookie, error)
Cookie 获取Cookie, 没有返回空字符串.
func (*HTTPResponse) Cookies ¶
func (resp *HTTPResponse) Cookies() []*http.Cookie
Cookies 获取Cookies, 没有返回空切片.
func (*HTTPResponse) FileNameWithCustom ¶
func (resp *HTTPResponse) FileNameWithCustom(nameField string) (string, error)
FileNameWithCustom 文件名.
func (*HTTPResponse) Header ¶
func (resp *HTTPResponse) Header(name string) string
Header 返回的Header.
func (*HTTPResponse) StatusCode ¶ added in v1.4.13
func (resp *HTTPResponse) StatusCode() int
StatusCode 状态码.
type ROpt ¶
type ROpt func(r *HTTPRequest)
func RWithContext ¶
func RWithCookie ¶
func RWithFile ¶
func RWithFile(file *FileUpload) ROpt
func RWithFiles ¶
func RWithFiles(files []*FileUpload) ROpt
func RWithHeader ¶
func RWithParams ¶
func RWithRetryWaitTime ¶ added in v1.4.13
func RWithTimeout ¶
func RWithTries ¶ added in v1.4.13
func RWithUserAgent ¶
Click to show internal directories.
Click to hide internal directories.