Documentation
¶
Index ¶
- Constants
- type Client
- func (client *Client) GetClientBaseUrl() string
- func (client *Client) GetClientBody() interface{}
- func (client *Client) GetClientCookie() string
- func (client *Client) GetClientDebug() bool
- func (client *Client) GetClientDebugFile() *os.File
- func (client *Client) GetClientHeaders() http.Header
- func (client *Client) GetClientQueryParams() url.Values
- func (client *Client) GetClientQueryParamsEncode() string
- func (client *Client) GetClientRetryNumber() int
- func (client *Client) GetClientTimeout() int
- func (client *Client) R() *Request
- func (client *Client) SetBaseURL(baseUrl string) *Client
- func (client *Client) SetBasicAuth(username, password string) *Client
- func (client *Client) SetCookie(cookie string) *Client
- func (client *Client) SetCookieJar(cookieJar http.CookieJar) *Client
- func (client *Client) SetDebug() *Client
- func (client *Client) SetDebugFile(logFileName string) *Client
- func (client *Client) SetFormDataQueryParams(params url.Values) *Client
- func (client *Client) SetHeader(key string, value interface{}) *Client
- func (client *Client) SetHeaders(headers map[string]interface{}) *Client
- func (client *Client) SetProxy(proxy string) *Client
- func (client *Client) SetQueryParam(key string, value any) *Client
- func (client *Client) SetQueryParamString(query string) *Client
- func (client *Client) SetQueryParams(params map[string]any) *Client
- func (client *Client) SetRetryNumber(num int) *Client
- func (client *Client) SetTimeout(timeout int) *Client
- func (client *Client) SetUserAgent(userAgent string) *Client
- type Request
- func (request *Request) Delete(url string) (*Response, error)
- func (request *Request) Get(url string) (*Response, error)
- func (request *Request) GetContentType() string
- func (request *Request) GetHost() string
- func (request *Request) GetMethod() string
- func (request *Request) GetPath() string
- func (request *Request) GetProto() string
- func (request *Request) GetQueryParams() url.Values
- func (request *Request) GetQueryParamsEncode() string
- func (request *Request) GetQueryParamsNopCloser() io.ReadCloser
- func (request *Request) GetRequestHeader() http.Header
- func (request *Request) GetUrl() string
- func (request *Request) Head(url string) (*Response, error)
- func (request *Request) Options(url string) (*Response, error)
- func (request *Request) Patch(url string) (*Response, error)
- func (request *Request) Post(url string) (*Response, error)
- func (request *Request) Put(url string) (*Response, error)
- func (request *Request) SetBody(body interface{}) *Request
- func (request *Request) SetContentType(contentType string) *Request
- func (request *Request) SetCookie(cookie *http.Cookie) *Request
- func (request *Request) SetCookies(cookie []*http.Cookie) *Request
- func (request *Request) SetHeader(key, value string) *Request
- func (request *Request) SetQueryParam(key string, value interface{}) *Request
- func (request *Request) SetQueryParams(query map[string]interface{}) *Request
- func (request *Request) SetQueryString(query string) *Request
- type Response
- func (response *Response) GetByte() []byte
- func (response *Response) GetCookies() []*http.Cookie
- func (response *Response) GetHeader() http.Header
- func (response *Response) GetStatus() string
- func (response *Response) GetStatusCode() int
- func (response *Response) Gjson() gjson.Result
- func (response *Response) Html() *goquery.Document
- func (response *Response) HtmlGbk() *goquery.Document
- func (response *Response) IsStatusOk() bool
- func (response *Response) Json(v any) error
- func (response *Response) String() string
- func (response *Response) StringGbk() string
Constants ¶
const ( // MethodGet HTTP method MethodGet = "GET" // MethodPost HTTP method MethodPost = "POST" // MethodPut HTTP method MethodPut = "PUT" // MethodDelete HTTP method MethodDelete = "DELETE" // MethodPatch HTTP method MethodPatch = "PATCH" // MethodHead HTTP method MethodHead = "HEAD" // MethodOptions HTTP method MethodOptions = "OPTIONS" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client 类型用于存储 HTTP 请求的相关信息。
func (*Client) GetClientBaseUrl ¶
GetClientBaseUrl 方法用于获取 HTTP 请求的 BaseUrl 部分。它返回一个 string 类型的参数。
func (*Client) GetClientBody ¶
func (client *Client) GetClientBody() interface{}
GetClientBody 方法用于获取 HTTP 请求的 Body 部分。它返回一个 interface{} 类型的参数。
func (*Client) GetClientCookie ¶
GetClientCookie 方法用于获取 HTTP 请求的 Cookie 部分。它返回一个 string 类型的参数。
func (*Client) GetClientDebug ¶
GetClientDebug 方法用于获取 HTTP 请求的 Debug 部分。它返回一个 bool 类型的参数。
func (*Client) GetClientDebugFile ¶
GetClientDebugFile 方法用于获取 HTTP 请求的 DebugFile 部分。它返回一个 *os.File 类型的参数。
func (*Client) GetClientHeaders ¶
GetClientHeaders 方法用于获取 HTTP 请求的 Header 部分。它返回一个 http.Header 类型的参数。
func (*Client) GetClientQueryParams ¶
GetClientQueryParams 方法用于获取 HTTP 请求的 Query 部分。它返回一个 url.Values 类型的参数。
func (*Client) GetClientQueryParamsEncode ¶
GetClientQueryParamsEncode 方法用于获取 HTTP 请求的 Query 部分。它返回一个 Encode 后的 string 类型的参数。
func (*Client) GetClientRetryNumber ¶
GetClientRetryNumber 方法用于获取 HTTP 请求的 RetryNumber 部分。它返回一个 int 类型的参数。
func (*Client) GetClientTimeout ¶
GetClientTimeout 方法用于获取 HTTP 请求的 Timeout 部分。它返回一个 int 类型的参数。
func (*Client) SetBaseURL ¶
SetBaseURL 方法用于设置HTTP请求的 BaseUrl 部分。它接收一个 string 类型的参数,该参数表示 BaseUrl 的值。
func (*Client) SetBasicAuth ¶
SetBasicAuth 方法用于设置 HTTP 请求的 BasicAuth 部分。它接收两个 string 类型的参数,分别表示用户名和密码。
func (*Client) SetCookieJar ¶
SetCookieJar 方法用于设置 HTTP 请求的 CookieJar 部分。它接收一个 http.CookieJar 类型的参数,该参数表示 CookieJar 的值。
func (*Client) SetDebugFile ¶
SetDebugFile 方法用于设置输出调试信息的文件。它接收一个 string 类型的参数,该参数表示文件名。
func (*Client) SetFormDataQueryParams ¶
SetFormDataQueryParams 方法用于设置 HTTP 请求的 Query 部分。它接收一个 url.Values 类型的参数,
func (*Client) SetHeaders ¶
SetHeaders 方法用于设置 HTTP 请求的 Header 部分。它接收一个 map[string]interface{} 类型的参数,
func (*Client) SetQueryParam ¶
SetQueryParam 方法用于设置 HTTP 请求的 Query 部分。它接收两个 string 类型的参数,
func (*Client) SetQueryParamString ¶
SetQueryParamString 方法用于设置 HTTP 请求的 Query 部分。它接收一个 string 类型的参数,
func (*Client) SetQueryParams ¶
SetQueryParams 方法用于设置 HTTP 请求的 Query 部分。它接收一个 map[string]interface{} 类型的参数,
func (*Client) SetRetryNumber ¶
SetRetryNumber 方法用于设置重试次数。它接收一个 int 类型的参数,该参数表示重试次数。
func (*Client) SetTimeout ¶
SetTimeout 方法用于设置 HTTP 请求的 Timeout 部分, timeout 单位为秒。它接收一个 int 类型的参数,该参数表示 Timeout 的值。
func (*Client) SetUserAgent ¶
SetUserAgent 方法用于设置 HTTP 请求的 User-Agent 部分。它接收一个 string 类型的参数,该参数表示 User-Agent 的值。
type Request ¶
type Request struct {
RequestRaw *http.Request // 指向 http.Request 的指针
// contains filtered or unexported fields
}
func (*Request) GetContentType ¶
GetContentType 方法用于获取 HTTP 请求的 Content-Type 部分的字符串。
func (*Request) GetQueryParams ¶
GetQueryParams 方法用于获取 HTTP 请求的 Query 部分的 url.Values。
func (*Request) GetQueryParamsEncode ¶
GetQueryParamsEncode 方法用于获取 HTTP 请求的 Query 部分的 URL 编码字符串。
func (*Request) GetQueryParamsNopCloser ¶
func (request *Request) GetQueryParamsNopCloser() io.ReadCloser
GetQueryParamsNopCloser 方法用于获取 HTTP 请求的 Query 部分的 ReadCloser。
func (*Request) GetRequestHeader ¶
GetRequestHeader 方法用于获取 HTTP 请求的 Header 部分的 http.Header。
func (*Request) SetBody ¶
SetBody 方法用于设置 HTTP 请求的 Body 部分。它接收一个 interface{} 类型的参数, 该参数可以是以下几种类型:string, []byte, map[string]interface{}, map[string]string, map[string]int, map[string]int64, map[string]float64, map[string]float32, map[string]bool。 对于不支持的类型,方法会设置 ContentLength 为 -1,并将 GetBody 方法设置为返回 nil。 如果成功设置了 body,方法会返回 Request 指针本身,以便进行链式调用。
func (*Request) SetContentType ¶
SetContentType 方法用于设置 HTTP 请求的 Content-Type 部分。它接收一个 string 类型的参数,
func (*Request) SetCookies ¶
SetCookies 方法用于设置 HTTP 请求的 Cookies 部分。它接收一个 []*http.Cookie 类型的参数,
func (*Request) SetQueryParam ¶
SetQueryParam 方法用于设置 HTTP 请求的 Query 部分。它接收两个 string 类型的参数,
func (*Request) SetQueryParams ¶
SetQueryParams 方法用于设置 HTTP 请求的 Query 部分。它接收一个 map[string]interface{} 类型的参数,
func (*Request) SetQueryString ¶
SetQueryString 方法用于设置 HTTP 请求的 Query 部分。它接收一个 string 类型的参数,
type Response ¶
type Response struct {
Result string // 响应体字符串结果
ResponseRaw *http.Response // 指向 http.Response 的指针
RequestSource *Request // 指向 Request 的指针
}
func (*Response) GetCookies ¶
GetCookies 方法用于获取 HTTP 响应的 Cookies 部分。
func (*Response) GetStatusCode ¶
GetStatusCode 方法用于获取 HTTP 响应的状态码。