Documentation ¶
Index ¶
- Constants
- Variables
- func NewRequestWithContext(ctx context.Context, method string, url string, headers map[string]string, ...) (*http.Request, error)
- type Client
- func AddURLQuery(key string, values ...string) *Client
- func AddURLQueryS(query string) *Client
- func New() *Client
- func SetBaseURL(url string) *Client
- func SetBody(in interface{}) *Client
- func SetContentType(contentType string) *Client
- func SetFromData(rows ...FromDataRow) *Client
- func SetHeader(key, value string) *Client
- func SetHeaders(headers map[string]string) *Client
- func SetProxy(proxy string) *Client
- func SetTimeout(duration time.Duration) *Client
- func SetURLQuery(key string, values ...string) *Client
- func SetURLQueryS(query string) *Client
- func SetUserAgent(ua string) *Client
- func UseClient(httpClient http.Client) *Client
- func UseDNS(dns ...string) *Client
- func (c Client) AddURLQuery(key string, values ...string) *Client
- func (c Client) AddURLQueryS(query string) *Client
- func (c Client) CallWithContext(ctx context.Context, method string, url string) (*Response, error)
- func (c Client) Delete(url string) (*Response, error)
- func (c Client) DeleteBaseURL() *Client
- func (c Client) DeleteHeaders(keys ...string) *Client
- func (c Client) DeleteProxy() *Client
- func (c Client) DeleteURLQuery() *Client
- func (c Client) DeleteWithContext(ctx context.Context, url string) (*Response, error)
- func (c Client) Do(req *http.Request) (*Response, error)
- func (c Client) Get(url string) (*Response, error)
- func (c Client) GetWithContext(ctx context.Context, url string) (*Response, error)
- func (c Client) Head(url string) (*Response, error)
- func (c Client) HeadWithContext(ctx context.Context, url string) (*Response, error)
- func (c Client) Options(url string) (*Response, error)
- func (c Client) OptionsWithContext(ctx context.Context, url string) (*Response, error)
- func (c Client) Patch(url string) (*Response, error)
- func (c Client) PatchWithContext(ctx context.Context, url string) (*Response, error)
- func (c Client) Post(url string) (*Response, error)
- func (c Client) PostWithContext(ctx context.Context, url string) (*Response, error)
- func (c Client) Put(url string) (*Response, error)
- func (c Client) PutWithContext(ctx context.Context, url string) (*Response, error)
- func (c Client) SetBaseURL(url string) *Client
- func (c Client) SetBody(body interface{}) *Client
- func (c Client) SetContentType(contentType string) *Client
- func (c Client) SetFromData(rows ...FromDataRow) *Client
- func (c Client) SetHeader(key, value string) *Client
- func (c Client) SetHeaders(headers map[string]string) *Client
- func (c Client) SetProxy(proxy string) *Client
- func (c Client) SetTimeout(duration time.Duration) *Client
- func (c Client) SetURLQuery(key string, values ...string) *Client
- func (c Client) SetURLQueryS(query string) *Client
- func (c Client) SetUserAgent(UA string) *Client
- func (c Client) UseDNS(dns ...string) *Client
- type FromDataRow
- type LinkError
- type Response
- func CallWithContext(ctx context.Context, method string, url string) (*Response, error)
- func Delete(url string) (*Response, error)
- func DeleteWithContext(ctx context.Context, url string) (*Response, error)
- func Do(req *http.Request) (*Response, error)
- func Get(url string) (*Response, error)
- func GetWithContext(ctx context.Context, url string) (*Response, error)
- func Head(url string) (*Response, error)
- func HeadWithContext(ctx context.Context, url string) (*Response, error)
- func Options(url string) (*Response, error)
- func OptionsWithContext(ctx context.Context, url string) (*Response, error)
- func Patch(url string) (*Response, error)
- func PatchWithContext(ctx context.Context, url string) (*Response, error)
- func Post(url string) (*Response, error)
- func PostWithContext(ctx context.Context, url string) (*Response, error)
- func Put(url string) (*Response, error)
- func PutWithContext(ctx context.Context, url string) (*Response, error)
Constants ¶
const ( // HeaderContentType 内容类型 HeaderContentType = "Content-Type" // HeaderContentDisposition 内容说明 HeaderContentDisposition = "Content-Disposition" // MIMEApplicationJSON json 类型 MIMEApplicationJSON = "application/json" // MIMETextHTML html 类型 MIMETextHTML = "text/html" // MIMETextHTMLUTF8 html 类型附带 utf-8 声明 MIMETextHTMLCharsetUTF8 = MIMETextHTML + "; " + charsetUTF8 // MIMEApplicationXML xml 类型(普通用户不可读) MIMEApplicationXML = "application/xml" // MIMETextXML xml 类型 (普通用户可读) MIMETextXML = "text/xml" // MIMETextPlain 文本类型 MIMETextPlain = "text/plain" // MIMEXWWWFormURLEncoded 简单表单 MIMEXWWWFormURLEncoded = "x-www-form-urlencoded" )
Variables ¶
var DefaultClient = New()
DefaultClient 默认客户端
Functions ¶
Types ¶
type Client ¶
type Client struct { BaseURL string // 基础 URL URLQuery stdURL.Values // URL 查询参数 Headers map[string]string // 头部信息 Body io.Reader // 内容 Client http.Client // 客户端 Error *LinkError // 错误 }
Client 客户端
func (Client) AddURLQuery ¶
AddURLQuery 添加 URL 查询参数
func (Client) AddURLQueryS ¶
AddURLQueryS 以 string 方式添加 URL 查询参数 name=niconiconi
func (Client) CallWithContext ¶
CallWithContext 使用指定 http 方法访问 url
func (Client) DeleteBaseURL ¶
DeleteBaseURL 删除基础 URL (如果有设置的话)
func (Client) DeleteHeaders ¶
DeleteHeaders 删除指定 headers
func (Client) DeleteWithContext ¶
DeleteWithContext 发送 DELETE 请求(可取消)
func (Client) GetWithContext ¶
GetWithContext 发送 GET 请求(可取消)
func (Client) HeadWithContext ¶
HeadWithContext 获取响应头(可取消)
func (Client) OptionsWithContext ¶
OptionsWithContext 获取目的资源所支持的通信选项(可取消)
func (Client) PatchWithContext ¶
PatchWithContext 发送 PATCH 请求(可取消)
func (Client) PostWithContext ¶
PostWithContext 发送 POST 请求(可取消)
func (Client) PutWithContext ¶
CallWithContext 发送 PUT 请求(可取消)
func (Client) SetBaseURL ¶
SetBaseURL 设置基础 URL 后续访问将默认拼接本URL
func (Client) SetContentType ¶
SetContentType 设置内容类型
func (Client) SetFromData ¶
func (c Client) SetFromData(rows ...FromDataRow) *Client
SetFromData 设置表单数据
func (Client) SetHeaders ¶
SetHeaders 设置 headers
func (Client) SetTimeout ¶
SetTimeout 设置超时时间
func (Client) SetURLQuery ¶
SetURLQuery 设置 URL 查询参数
func (Client) SetURLQueryS ¶
SetURLQueryS 以 string 的方式设置查询参数
type FromDataRow ¶
type FromDataRow struct { Key string // 键 Value string // 值 (如果上传的是文件则这里是文件名) Data io.Reader // 数据 (如果上传的是文件则这里是文件不然则为空) }
FromDataRow formData 单条数据
type Response ¶
Response 包装 http.Response
func CallWithContext ¶
CallWithContext 使用指定 http 方法访问 url
func DeleteWithContext ¶
DeleteWithContext 发送 DELETE 请求(可取消)
func GetWithContext ¶
GetWithContext 发送 GET 请求(可取消)
func HeadWithContext ¶
HeadWithContext 获取响应头(可取消)
func OptionsWithContext ¶
OptionsWithContext 获取目的资源所支持的通信选项(可取消)
func PatchWithContext ¶
PatchWithContext 发送 PATCH 请求(可取消)
func PostWithContext ¶
PostWithContext 发送 POST 请求(可取消)
func PutWithContext ¶
PutWithContext 发送 PUT 请求(可取消)