Documentation ¶
Index ¶
- func ClientIp(r *http.Request) string
- func DeCode(s string) string
- func GetParamsString(src interface{}) string
- func GetRandomUserAgent() string
- func GetRandomUserAgentSystem() string
- func IsWechatMiniProgramRequest(ginCtx *gin.Context, appid string) error
- func LenCode(s string) string
- func ParseQuery(s string) map[string][]string
- type App
- func (app *App) Get(ctx context.Context, uri ...string) (httpResponse Response, err error)
- func (app *App) Post(ctx context.Context, uri ...string) (httpResponse Response, err error)
- func (app *App) Request(ctx context.Context) (httpResponse Response, err error)
- func (app *App) SetAuthToken(token string)
- func (app *App) SetContentTypeForm()
- func (app *App) SetContentTypeJson()
- func (app *App) SetContentTypeXml()
- func (app *App) SetCookie(value string)
- func (app *App) SetDebug()
- func (app *App) SetHeader(key, value string)
- func (app *App) SetHeaders(headers Headers)
- func (app *App) SetMethod(method string)
- func (app *App) SetP12Cert(content *tls.Certificate)
- func (app *App) SetParam(key string, value interface{})
- func (app *App) SetParams(params *Params)
- func (app *App) SetTlsVersion(minVersion, maxVersion uint16)
- func (app *App) SetUri(uri string)
- func (app *App) SetUserAgent(ua string)
- type Headers
- type Params
- func (p *Params) DeepCopy() *Params
- func (p *Params) Get(key string) interface{}
- func (p *Params) HasData() bool
- func (p *Params) MarshalXML() (reader io.Reader, err error)
- func (p *Params) Set(key string, value interface{})
- func (p *Params) SetParams(params *Params)
- func (p *Params) ToMap() map[string]interface{}
- type Response
- func (r *Response) HeaderHtml() bool
- func (r *Response) HeaderIsImg() bool
- func (r *Response) HeaderIsJpeg() bool
- func (r *Response) HeaderIsJpg() bool
- func (r *Response) HeaderIsPng() bool
- func (r *Response) HeaderJson() bool
- func (r *Response) HeaderTextHtml() bool
- func (r *Response) HeaderXHtml() bool
- type ResponseUrlParse
- type UriParse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientIp ¶
ClientIp 尽最大努力实现获取客户端 IP 的算法。 解析 X-Real-IP 和 X-Forwarded-For 以便于反向代理(nginx 或 haproxy)可以正常工作。
func GetParamsString ¶ added in v1.0.47
func GetParamsString(src interface{}) string
GetParamsString 获取参数字符串
func GetRandomUserAgentSystem ¶ added in v1.0.47
func GetRandomUserAgentSystem() string
GetRandomUserAgentSystem 获取系统随机UA
func IsWechatMiniProgramRequest ¶ added in v1.0.113
func ParseQuery ¶ added in v1.0.47
ParseQuery 获取URL参数 https://studygolang.com/articles/2876
Types ¶
type App ¶ added in v1.0.47
type App struct { Uri string // 全局请求地址,没有设置url才会使用 Error error // 错误 // contains filtered or unexported fields }
App 实例
func (*App) SetAuthToken ¶ added in v1.0.47
SetAuthToken 设置身份验证令牌
func (*App) SetContentTypeForm ¶ added in v1.0.47
func (app *App) SetContentTypeForm()
SetContentTypeForm 设置FORM格式
func (*App) SetContentTypeJson ¶ added in v1.0.47
func (app *App) SetContentTypeJson()
SetContentTypeJson 设置JSON格式
func (*App) SetContentTypeXml ¶ added in v1.0.47
func (app *App) SetContentTypeXml()
SetContentTypeXml 设置XML格式
func (*App) SetHeaders ¶ added in v1.0.47
SetHeaders 批量设置请求头
func (*App) SetP12Cert ¶ added in v1.0.47
func (app *App) SetP12Cert(content *tls.Certificate)
SetP12Cert 设置证书
func (*App) SetTlsVersion ¶ added in v1.0.101
SetTlsVersion 设置TLS版本
func (*App) SetUserAgent ¶ added in v1.0.47
SetUserAgent 设置用户代理,空字符串就随机设置
type Headers ¶ added in v1.0.47
Headers 头部信息
func NewNewHeadersWith ¶ added in v1.0.47
NewNewHeadersWith 头部信息使用
func (Headers) SetHeaders ¶ added in v1.0.47
SetHeaders 批量设置头部信息
type Params ¶ added in v1.0.47
type Params struct {
// contains filtered or unexported fields
}
Params 参数
func NewParamsWith ¶ added in v1.0.47
NewParamsWith 参数使用
func (*Params) MarshalXML ¶ added in v1.0.47
MarshalXML 结构体转xml
type Response ¶ added in v1.0.47
type Response struct { RequestId string //【请求】编号 RequestUri string //【请求】链接 RequestParams *Params //【请求】参数 RequestMethod string //【请求】方式 RequestHeader Headers //【请求】头部 RequestCookie string //【请求】Cookie RequestTime time.Time //【请求】时间 ResponseHeader http.Header //【返回】头部 ResponseStatus string //【返回】状态 ResponseStatusCode int //【返回】状态码 ResponseBody []byte //【返回】内容 ResponseContentLength int64 //【返回】大小 ResponseTime time.Time //【返回】时间 }
Response 返回内容
func (*Response) HeaderHtml ¶ added in v1.0.52
HeaderHtml 判断是否为Html
func (*Response) HeaderIsImg ¶ added in v1.0.52
HeaderIsImg 判断是否为图片
func (*Response) HeaderIsJpeg ¶ added in v1.0.52
HeaderIsJpeg 判断是否为jpeg图片
func (*Response) HeaderIsJpg ¶ added in v1.0.52
HeaderIsJpg 判断是否为Jpg图片
func (*Response) HeaderIsPng ¶ added in v1.0.52
HeaderIsPng 判断是否为Png图片
func (*Response) HeaderJson ¶ added in v1.0.52
HeaderJson 判断是否为Json数据
func (*Response) HeaderTextHtml ¶ added in v1.0.52
HeaderTextHtml 判断是否为Html
func (*Response) HeaderXHtml ¶ added in v1.0.52
HeaderXHtml 判断是否为Html
type ResponseUrlParse ¶ added in v1.0.47
type ResponseUrlParse struct { Uri string `json:"uri"` // URI Urn string `json:"urn"` // URN Url string `json:"url"` // URL Scheme string `json:"scheme"` // 协议 Host string `json:"host"` // 主机 Hostname string `json:"hostname"` // 主机名 Port string `json:"port"` // 端口 Path string `json:"path"` // 路径 RawQuery string `json:"raw_query"` // 参数 ? Fragment string `json:"fragment"` // 片段 # }
ResponseUrlParse 返回参数
type UriParse ¶ added in v1.0.47
type UriParse struct {
// contains filtered or unexported fields
}
func (*UriParse) Parse ¶ added in v1.0.52
func (u *UriParse) Parse() (resp ResponseUrlParse)
Parse 解析URl
func (*UriParse) UriFilterExcludeQueryString ¶ added in v1.0.52
UriFilterExcludeQueryString 过滤掉url中的参数