Documentation ¶
Index ¶
- Constants
- type Gapi
- func (p *Gapi) Cache() *cache.Cache
- func (p *Gapi) ClearCookies()
- func (p *Gapi) Client() *http.Client
- func (p *Gapi) Do(api *GapiApi) (presp *GapiResponse, e error)
- func (p *Gapi) EndpointPATH(path string, values url.Values) *url.URL
- func (p *Gapi) EndpointURL(urlString string, values url.Values) (*url.URL, error)
- func (p *Gapi) GetGHeader() http.Header
- func (p *Gapi) GetURL() *url.URL
- func (p *Gapi) Request(ctx context.Context, method, url string, body io.Reader, ...) (*http.Response, error)
- func (p *Gapi) SetGHeader(m http.Header)
- func (p *Gapi) SetOptions(opts *Options) error
- func (p *Gapi) Timeout() time.Duration
- type GapiApi
- func (a *GapiApi) AddHeader(key string, value string) *GapiApi
- func (a *GapiApi) AddValue(key string, value string) *GapiApi
- func (a *GapiApi) DelHeader(key string)
- func (a *GapiApi) DelValue(key string)
- func (a *GapiApi) GetBody() []byte
- func (a *GapiApi) GetError() error
- func (a *GapiApi) GetHeader(key string) string
- func (a *GapiApi) GetHeaders(key string) []string
- func (a *GapiApi) GetValue(key string) string
- func (a *GapiApi) HasValue(key string) bool
- func (a *GapiApi) SetBody(body []byte) *GapiApi
- func (a *GapiApi) SetError(e error) *GapiApi
- func (a *GapiApi) SetHeader(key string, value string) *GapiApi
- func (a *GapiApi) SetHeaders(value map[string]string) *GapiApi
- func (a *GapiApi) SetHijack(hijack func(p *Gapi, req *http.Request) error) *GapiApi
- func (a *GapiApi) SetRespHijack(hijack func(resp *GapiResponse, setBody func(body []byte)) error) *GapiApi
- func (a *GapiApi) SetValue(key string, value string) *GapiApi
- func (a *GapiApi) SetValues(values map[string]string) *GapiApi
- type GapiResponse
- func (r *GapiResponse) Content() ([]byte, error)
- func (r *GapiResponse) GJSON() (*gjson.Result, error)
- func (r *GapiResponse) Gapi() *Gapi
- func (r *GapiResponse) JSON(v ...interface{}) (interface{}, error)
- func (r *GapiResponse) OK() bool
- func (r *GapiResponse) Raw() []byte
- func (r *GapiResponse) Reason() string
- func (r *GapiResponse) Text() (string, error)
- func (r *GapiResponse) URL() (*url.URL, error)
- type Options
Constants ¶
View Source
const ( HeaderAccept = "Accept" HeaderAcceptCharset = "Accept-Charset" HeaderAcceptEncoding = "Accept-Encoding" HeaderAcceptLanguage = "Accept-Language" HeaderAuthorization = "Authorization" HeaderCacheControl = "Cache-Control" HeaderContentLength = "Content-Length" HeaderContentMD5 = "Content-MD5" HeaderContentType = "Content-Type" HeaderDoNotTrack = "DNT" HeaderIfMatch = "If-Match" HeaderIfModifiedSince = "If-Modified-Since" HeaderIfNoneMatch = "If-None-Match" HeaderIfRange = "If-Range" HeaderIfUnmodifiedSince = "If-Unmodified-Since" HeaderMaxForwards = "Max-Forwards" HeaderProxyAuthorization = "Proxy-Authorization" HeaderPragma = "Pragma" HeaderRange = "Range" HeaderReferer = "Referer" HeaderUserAgent = "User-Agent" HeaderTE = "TE" HeaderVia = "Via" HeaderWarning = "Warning" HeaderCookie = "Cookie" HeaderOrigin = "Origin" HeaderAcceptDatetime = "Accept-Datetime" HeaderXRequestedWith = "X-Requested-With" HeaderAccessControlAllowOrigin = "Access-Control-Allow-Origin" HeaderAccessControlAllowMethods = "Access-Control-Allow-Methods" HeaderAccessControlAllowHeaders = "Access-Control-Allow-Headers" HeaderAccessControlAllowCredentials = "Access-Control-Allow-Credentials" HeaderAccessControlExposeHeaders = "Access-Control-Expose-Headers" HeaderAccessControlMaxAge = "Access-Control-Max-Age" HeaderAccessControlRequestMethod = "Access-Control-Request-Method" HeaderAccessControlRequestHeaders = "Access-Control-Request-Headers" HeaderAcceptPatch = "Accept-Patch" HeaderAcceptRanges = "Accept-Ranges" HeaderAllow = "Allow" HeaderContentEncoding = "Content-Encoding" HeaderContentLanguage = "Content-Language" HeaderContentLocation = "Content-Location" HeaderContentDisposition = "Content-Disposition" HeaderContentRange = "Content-Range" HeaderETag = "ETag" HeaderExpires = "Expires" HeaderLastModified = "Last-Modified" HeaderLink = "Link" HeaderLocation = "Location" HeaderP3P = "P3P" HeaderProxyAuthenticate = "Proxy-Authenticate" HeaderRefresh = "Refresh" HeaderRetryAfter = "Retry-After" HeaderServer = "Server" HeaderSetCookie = "Set-Cookie" HeaderStrictTransportSecurity = "Strict-Transport-Security" HeaderTransferEncoding = "Transfer-Encoding" HeaderUpgrade = "Upgrade" HeaderVary = "Vary" HeaderWWWAuthenticate = "WWW-Authenticate" // Non-Standard HeaderXFrameOptions = "X-Frame-Options" HeaderXXSSProtection = "X-XSS-Protection" HeaderContentSecurityPolicy = "Content-Security-Policy" HeaderXContentSecurityPolicy = "X-Content-Security-Policy" HeaderXWebKitCSP = "X-WebKit-CSP" HeaderXContentTypeOptions = "X-Content-Type-Options" HeaderXPoweredBy = "X-Powered-By" HeaderXUACompatible = "X-UA-Compatible" HeaderXForwardedProto = "X-Forwarded-Proto" HeaderXHTTPMethodOverride = "X-HTTP-Method-Override" HeaderXForwardedFor = "X-Forwarded-For" HeaderXRealIP = "X-Real-IP" HeaderXCSRFToken = "X-CSRF-Token" HeaderXRatelimitLimit = "X-Ratelimit-Limit" HeaderXRatelimitRemaining = "X-Ratelimit-Remaining" HeaderXRatelimitReset = "X-Ratelimit-Reset" HeaderXFronURLEncoded = "application/x-www-form-urlencoded" // User-Agent DefaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36" IDefaultosDeviceUserAgent = "" /* 137-byte string literal not displayed */ )
HTTP headers
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gapi ¶
type Gapi struct {
// contains filtered or unexported fields
}
Gapi 客户端
func (*Gapi) ClearCookies ¶
func (p *Gapi) ClearCookies()
清除 cookie 将cookiejar中的所有cookie清除 当设置了PHPSESSID时, 可以使用这个方法来清除
func (*Gapi) Do ¶
func (p *Gapi) Do(api *GapiApi) (presp *GapiResponse, e error)
请求Gapi接口 (接口需通过api包里面的方法生成)
func (*Gapi) EndpointPATH ¶
生成URL 提供Gapi站点的path和参数返回完整的URL
func (*Gapi) EndpointURL ¶
生成URL 提供任意的url和参数返回完整的URL
func (*Gapi) GetGHeader ¶
func (*Gapi) Request ¶
func (p *Gapi) Request(ctx context.Context, method, url string, body io.Reader, hijack func(c *http.Client, req *http.Request) error) (*http.Response, error)
创建一个新的http.Client 并且有一个ref可以设置自定义选项然后通过client.Do()来发送请求 将返回原始的http.Response
func (*Gapi) SetGHeader ¶
func (*Gapi) SetOptions ¶
type GapiApi ¶
type GapiApi struct { Method string URL string Headers http.Header Values url.Values Body []byte Error error Hijack func(p *Gapi, req *http.Request) error RespHijack func(resp *GapiResponse, setBody func(b []byte)) error }
Gapi 接口
func (*GapiApi) SetHeaders ¶
Headers 设置Headers
func (*GapiApi) SetRespHijack ¶
func (a *GapiApi) SetRespHijack(hijack func(resp *GapiResponse, setBody func(body []byte)) error) *GapiApi
设置请求后的Hijack
type GapiResponse ¶
Gapi接口返回
func (*GapiResponse) GJSON ¶
func (r *GapiResponse) GJSON() (*gjson.Result, error)
获取JSON响应内容 可以传指针类型的接收者
func (*GapiResponse) Gapi ¶
func (r *GapiResponse) Gapi() *Gapi
func (*GapiResponse) JSON ¶
func (r *GapiResponse) JSON(v ...interface{}) (interface{}, error)
获取JSON响应内容 可以传指针类型的接收者
Source Files ¶
Click to show internal directories.
Click to hide internal directories.