Documentation
¶
Overview ¶
Package httputil 是一个 http client 辅助类,基于 Resty 库实现
Index ¶
- Variables
- func Download(url, output string, callbacks ...Callback) error
- func Get(url string, callbacks ...Callback) error
- func GetQuery(url string, query map[string]string, callbacks ...Callback) error
- func GetQueryWithContext(ctx context.Context, url string, query map[string]string, ...) error
- func GetTopDomain(host string) string
- func GetWithContext(ctx context.Context, url string, callbacks ...Callback) error
- func New() *httpClient
- func NewDownload() *downloadHttpClient
- func NewSSE() *sseHttpClient
- func PostForm(url string, data map[string]string, callbacks ...Callback) error
- func PostFormWithContext(ctx context.Context, url string, data map[string]string, callbacks ...Callback) error
- func PostGzJSON(url string, body any, callbacks ...Callback) error
- func PostGzJSONWithContext(ctx context.Context, url string, body any, callbacks ...Callback) error
- func PostJSON(url string, body any, callbacks ...Callback) error
- func PostJSONWithContext(ctx context.Context, url string, body any, callbacks ...Callback) error
- func SSEPostJSON(url string, body any, callbacks ...Callback) (string, error)
- func SSEPostJSONWithContext(ctx context.Context, url string, body any, callbacks ...Callback) (string, error)
- type Builder
- type Callback
- type OpenAPIClient
- func (o *OpenAPIClient) Get(requestUrl string, params url.Values) ([]byte, error)
- func (o *OpenAPIClient) PostFile(requestUrl string, params url.Values, path string) ([]byte, error)
- func (o *OpenAPIClient) PostForm(requestUrl string, params url.Values, form map[string]string) ([]byte, error)
- func (o *OpenAPIClient) PostJson(requestUrl string, params url.Values, jsonData map[string]interface{}) ([]byte, error)
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = New()
var DefaultDownloadClient = NewDownload()
var DefaultSSEClient = NewSSE()
Functions ¶
func GetQueryWithContext ¶
func GetQueryWithContext(ctx context.Context, url string, query map[string]string, callbacks ...Callback) error
GetQueryWithContext 发送 HTTP/GET 请求,query 参数通过 map 传递进来,成功时回调 callbacks 支持 context
func GetTopDomain ¶
func GetWithContext ¶
GetWithContext 发送 HTTP/GET 请求,成功时回调 callbacks 支持 context
func NewDownload ¶
func NewDownload() *downloadHttpClient
func PostFormWithContext ¶
func PostFormWithContext(ctx context.Context, url string, data map[string]string, callbacks ...Callback) error
PostFormWithContext 发送 HTTP/POST 请求,数据格式 x-www-form-urlencoded ,成功时回调 callbacks 支持 context
func PostGzJSONWithContext ¶
PostJSONWithContext 发送 HTTP/POST 请求,数据格式 JSON ,成功时回调 callbacks 支持 context
func PostJSON ¶
PostJSON 发送 HTTP/POST 请求,数据格式 JSON ,成功时回调 callbacks Supported request body data types is `string`, `[]byte`, `struct`, `map`, `slice` and `io.Reader`. Body value can be pointer or non-pointer. Automatic marshalling for JSON and XML content type, if it is `struct`, `map`, or `slice`.
func PostJSONWithContext ¶
PostJSONWithContext 发送 HTTP/POST 请求,数据格式 JSON ,成功时回调 callbacks 支持 context
Types ¶
type OpenAPIClient ¶
func NewOpenAPIClient ¶
func NewOpenAPIClient(APPkey string, Secert string) *OpenAPIClient