Documentation ¶
Index ¶
- Variables
- type AspectModel
- type HttpClient
- func (client HttpClient) Do(req *HttpRequest) (*HttpResponse, error)
- func (client HttpClient) Get(url string) (*HttpResponse, error)
- func (client HttpClient) GetAspectArgs() []interface{}
- func (client HttpClient) GetWithCookieAndHeader(url string, cookie, header map[string]string) (*HttpResponse, error)
- func (client HttpClient) Post(url string) (*HttpResponse, error)
- func (client HttpClient) PostWithCookieHeaderAndForm(url string, cookie, header, form map[string]string) (*HttpResponse, error)
- func (client HttpClient) PostWithCookieHeaderAndIoData(url string, cookie, header map[string]string, data *io.Reader) (*HttpResponse, error)
- func (client HttpClient) PostWithForm(url string, form map[string]string) (*HttpResponse, error)
- func (client HttpClient) PostWithIoData(url string, data *io.Reader) (*HttpResponse, error)
- type HttpMethod
- type HttpRequest
- func (hr *HttpRequest) AppendCookie(name, value string) *HttpRequest
- func (hr *HttpRequest) AppendCookies(cookies map[string]string) *HttpRequest
- func (hr *HttpRequest) AppendForm(name, value string) *HttpRequest
- func (hr *HttpRequest) AppendForms(forms map[string]string) *HttpRequest
- func (hr *HttpRequest) AppendHeader(name, value string) *HttpRequest
- func (hr *HttpRequest) AppendHeaders(headers map[string]string) *HttpRequest
- func (hr *HttpRequest) AppendQueries(params map[string]string) *HttpRequest
- func (hr *HttpRequest) AppendQuery(name, value string) *HttpRequest
- func (hr *HttpRequest) BuildRequest() (*http.Request, error)
- func (hr *HttpRequest) ClearAllCookie() *HttpRequest
- func (hr *HttpRequest) ClearAllForm() *HttpRequest
- func (hr *HttpRequest) ClearAllHeader() *HttpRequest
- func (hr *HttpRequest) ClearAllQuery() *HttpRequest
- func (hr *HttpRequest) DelCookie(name string) *HttpRequest
- func (hr *HttpRequest) DelForm(name string) *HttpRequest
- func (hr *HttpRequest) DelHeader(name string) *HttpRequest
- func (hr *HttpRequest) DelQuery(name string) *HttpRequest
- func (hr *HttpRequest) GetCookie(name string) string
- func (hr *HttpRequest) GetForm(name string) string
- func (hr *HttpRequest) GetHeader(name string) string
- func (hr *HttpRequest) GetQuery(name string) string
- func (hr *HttpRequest) ReplaceCookies(cookies map[string]string)
- func (hr *HttpRequest) ReplaceForms(header map[string]string) *HttpRequest
- func (hr *HttpRequest) ReplaceHeaders(header map[string]string) *HttpRequest
- func (hr *HttpRequest) ReplaceQuery(param map[string]string) *HttpRequest
- func (hr *HttpRequest) SetFileBody(file *os.File) *HttpRequest
- func (hr *HttpRequest) SetFileBodyPath(path string) *HttpRequest
- func (hr *HttpRequest) SetJsonBody(json string) *HttpRequest
- func (hr *HttpRequest) SetJsonBodyStruct(v interface{}) *HttpRequest
- func (hr *HttpRequest) SetMethod(method HttpMethod) *HttpRequest
- func (hr *HttpRequest) SetReaderBody(reader *io.Reader) *HttpRequest
- func (hr *HttpRequest) SetURL(URL string) *HttpRequest
- type HttpResponse
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultClient = &HttpClient{ &http.Client{Timeout: 5 * time.Second}, defaultAspect, defaultAspect, defaultAspect, defaultAspect, defaultAspect, nil, }
Functions ¶
This section is empty.
Types ¶
type AspectModel ¶
type AspectModel func(*HttpRequest, *HttpResponse, ...interface{})
AspectModel 切片模组
type HttpClient ¶
type HttpClient struct { BeforeClientBuild AspectModel AfterClientBuild AspectModel BeforeRequestBuild AspectModel AfterRequestBuild AspectModel AfterResponseCreate AspectModel AspectArgs []interface{} // Only the most recent assignment will be kept // contains filtered or unexported fields }
HttpClient A client send request
func GetDefaultClient ¶
func GetDefaultClient() *HttpClient
GetDefaultClient !!! This method will not execute BeforeClientBuild and AfterClientBuild. 这个方法不会执行 BeforeClientBuild 和 AfterClientBuild。
func NewClient ¶
func NewClient(client *http.Client) *HttpClient
NewClient !!! This method will not execute BeforeClientBuild and AfterClientBuild. 这个方法不会执行 BeforeClientBuild 和 AfterClientBuild。
func NewClientX ¶
func NewClientX(client *http.Client, beforeClientBuild, afterClientBuild, beforeRequestBuild, afterRequestBuild, afterResponseCreate AspectModel, args ...interface{}) *HttpClient
NewClientX This method execute BeforeClientBuild and AfterClientBuild. 这个方法执行 BeforeClientBuild 和 AfterClientBuild。
func (HttpClient) Do ¶
func (client HttpClient) Do(req *HttpRequest) (*HttpResponse, error)
Do run with Aspect
func (HttpClient) Get ¶
func (client HttpClient) Get(url string) (*HttpResponse, error)
func (HttpClient) GetAspectArgs ¶
func (client HttpClient) GetAspectArgs() []interface{}
func (HttpClient) GetWithCookieAndHeader ¶
func (client HttpClient) GetWithCookieAndHeader(url string, cookie, header map[string]string) (*HttpResponse, error)
func (HttpClient) Post ¶
func (client HttpClient) Post(url string) (*HttpResponse, error)
func (HttpClient) PostWithCookieHeaderAndForm ¶
func (client HttpClient) PostWithCookieHeaderAndForm(url string, cookie, header, form map[string]string) (*HttpResponse, error)
func (HttpClient) PostWithCookieHeaderAndIoData ¶
func (client HttpClient) PostWithCookieHeaderAndIoData(url string, cookie, header map[string]string, data *io.Reader) (*HttpResponse, error)
func (HttpClient) PostWithForm ¶
func (client HttpClient) PostWithForm(url string, form map[string]string) (*HttpResponse, error)
func (HttpClient) PostWithIoData ¶
func (client HttpClient) PostWithIoData(url string, data *io.Reader) (*HttpResponse, error)
type HttpMethod ¶
type HttpMethod string
const ( GET HttpMethod = http.MethodGet POST HttpMethod = http.MethodPost DELETE HttpMethod = http.MethodDelete PUT HttpMethod = http.MethodPut PATCH HttpMethod = http.MethodPatch OPTIONS HttpMethod = http.MethodOptions )
func (HttpMethod) String ¶
func (hm HttpMethod) String() string
type HttpRequest ¶
type HttpRequest struct { Method HttpMethod // Queries will overwrite the queries in the URL // Queries 会覆盖 URL 中的参数 URL string Cookies map[string]string Headers map[string]string // Queries will overwrite the queries in the URL // Queries 会覆盖 URL 中的参数 Queries map[string]string // When creating the HttpRequest, we have already added "Content-Type: application/x-www-form-urlencoded" for you . // 在创建 HttpRequest 的时候,我们已经帮你加好了 Content-Type: application/x-www-form-urlencoded // If you want to modify, please add "Content-Type" sauce to the Headers // 如果你想修改的话,请在 Headers 中加入“Content-Type” // The HTTP client ignores Form and uses Body instead. Forms map[string]string // When creating the HttpRequest, we have already added "Content-Type: application/json" for you . // 在创建 HttpRequest 的时候,我们已经帮你加好了 Content-Type // If you want to modify, please add "Content-Type" sauce to the Headers // 如果你想修改的话,请在 Headers 中加入“Content-Type” Json *string // When creating the HttpRequest, we have already added "Content-Type: text/xml" for you . // 在创建 HttpRequest 的时候,我们已经帮你加好了 Content-Type: application/x-www-form-urlencoded // If you want to modify, please add "Content-Type" sauce to the Headers // 如果你想修改的话,请在 Headers 中加入“Content-Type” Xml *string // When creating the HttpRequest, we have already added "Content-Type: multipart/form-data" for you . // 在创建 HttpRequest 的时候,我们已经帮你加好了 Content-Type // If you want to modify, please add "Content-Type: " sauce to the Headers // 如果你想修改的话,请在 Headers 中加入“Content-Type” File *os.File // Please add "Content-Type" sauce to the Headers // 请在 Headers 中加入“Content-Type” ReaderBody *io.Reader }
HttpRequest Forms > Json > Xml > File > ReaderBody
func NewHttpRequest ¶
func NewHttpRequest() *HttpRequest
func (*HttpRequest) AppendCookie ¶
func (hr *HttpRequest) AppendCookie(name, value string) *HttpRequest
func (*HttpRequest) AppendCookies ¶
func (hr *HttpRequest) AppendCookies(cookies map[string]string) *HttpRequest
func (*HttpRequest) AppendForm ¶
func (hr *HttpRequest) AppendForm(name, value string) *HttpRequest
func (*HttpRequest) AppendForms ¶
func (hr *HttpRequest) AppendForms(forms map[string]string) *HttpRequest
func (*HttpRequest) AppendHeader ¶
func (hr *HttpRequest) AppendHeader(name, value string) *HttpRequest
func (*HttpRequest) AppendHeaders ¶
func (hr *HttpRequest) AppendHeaders(headers map[string]string) *HttpRequest
func (*HttpRequest) AppendQueries ¶
func (hr *HttpRequest) AppendQueries(params map[string]string) *HttpRequest
func (*HttpRequest) AppendQuery ¶
func (hr *HttpRequest) AppendQuery(name, value string) *HttpRequest
func (*HttpRequest) BuildRequest ¶
func (hr *HttpRequest) BuildRequest() (*http.Request, error)
func (*HttpRequest) ClearAllCookie ¶
func (hr *HttpRequest) ClearAllCookie() *HttpRequest
func (*HttpRequest) ClearAllForm ¶
func (hr *HttpRequest) ClearAllForm() *HttpRequest
func (*HttpRequest) ClearAllHeader ¶
func (hr *HttpRequest) ClearAllHeader() *HttpRequest
func (*HttpRequest) ClearAllQuery ¶
func (hr *HttpRequest) ClearAllQuery() *HttpRequest
func (*HttpRequest) DelCookie ¶
func (hr *HttpRequest) DelCookie(name string) *HttpRequest
func (*HttpRequest) DelForm ¶
func (hr *HttpRequest) DelForm(name string) *HttpRequest
func (*HttpRequest) DelHeader ¶
func (hr *HttpRequest) DelHeader(name string) *HttpRequest
func (*HttpRequest) DelQuery ¶
func (hr *HttpRequest) DelQuery(name string) *HttpRequest
func (*HttpRequest) GetCookie ¶
func (hr *HttpRequest) GetCookie(name string) string
func (*HttpRequest) GetForm ¶
func (hr *HttpRequest) GetForm(name string) string
func (*HttpRequest) GetHeader ¶
func (hr *HttpRequest) GetHeader(name string) string
func (*HttpRequest) GetQuery ¶
func (hr *HttpRequest) GetQuery(name string) string
func (*HttpRequest) ReplaceCookies ¶
func (hr *HttpRequest) ReplaceCookies(cookies map[string]string)
func (*HttpRequest) ReplaceForms ¶
func (hr *HttpRequest) ReplaceForms(header map[string]string) *HttpRequest
func (*HttpRequest) ReplaceHeaders ¶
func (hr *HttpRequest) ReplaceHeaders(header map[string]string) *HttpRequest
func (*HttpRequest) ReplaceQuery ¶
func (hr *HttpRequest) ReplaceQuery(param map[string]string) *HttpRequest
func (*HttpRequest) SetFileBody ¶
func (hr *HttpRequest) SetFileBody(file *os.File) *HttpRequest
func (*HttpRequest) SetFileBodyPath ¶
func (hr *HttpRequest) SetFileBodyPath(path string) *HttpRequest
func (*HttpRequest) SetJsonBody ¶
func (hr *HttpRequest) SetJsonBody(json string) *HttpRequest
func (*HttpRequest) SetJsonBodyStruct ¶ added in v1.0.4
func (hr *HttpRequest) SetJsonBodyStruct(v interface{}) *HttpRequest
func (*HttpRequest) SetMethod ¶
func (hr *HttpRequest) SetMethod(method HttpMethod) *HttpRequest
func (*HttpRequest) SetReaderBody ¶
func (hr *HttpRequest) SetReaderBody(reader *io.Reader) *HttpRequest
func (*HttpRequest) SetURL ¶
func (hr *HttpRequest) SetURL(URL string) *HttpRequest
type HttpResponse ¶
type HttpResponse struct { Headers map[string]string Body io.ReadCloser // contains filtered or unexported fields }
func CreateResponse ¶
func CreateResponse(resp *http.Response) *HttpResponse
func (*HttpResponse) GetRespStr ¶
func (hr *HttpResponse) GetRespStr() string
func (*HttpResponse) GetResponse ¶
func (hr *HttpResponse) GetResponse() *http.Response
GetResponse It return http.Response struct
func (*HttpResponse) ParseJson ¶
func (hr *HttpResponse) ParseJson(v interface{})
Click to show internal directories.
Click to hide internal directories.