Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultClient() *http.Client
- func NewClient(timeout time.Duration) *http.Client
- func NowUnix() int64
- func SetDefaultClient(client *http.Client)
- type File
- type Request
- func (r *Request) AddCookie(c *http.Cookie) *Request
- func (r *Request) AddCookies(cookies []*http.Cookie) *Request
- func (r *Request) AddHeader(key string, value string) *Request
- func (r *Request) AddQueryParam(key string, value string) *Request
- func (r *Request) CustomMethod(method, targetUrl string) *Request
- func (r *Request) Delete(targetUrl string) *Request
- func (r *Request) DisableKeepAlive() *Request
- func (r *Request) EnableKeepAlive() *Request
- func (r *Request) Get(targetUrl string) *Request
- func (r *Request) Head(targetUrl string) *Request
- func (r *Request) Options(targetUrl string) *Request
- func (r *Request) Patch(targetUrl string) *Request
- func (r *Request) Post(targetUrl string) *Request
- func (r *Request) Put(targetUrl string) *Request
- func (r *Request) Send() *Result
- func (r *Request) SendBytes(body []byte) *Result
- func (r *Request) SendFile(absFile, fileName, fieldName string, fileContent []byte) *Result
- func (r *Request) SendFiles(files []*File) *Result
- func (r *Request) SendForm(content interface{}) *Result
- func (r *Request) SendJson(content interface{}) *Result
- func (r *Request) SendString(body string) *Result
- func (r *Request) SetBasicAuth(username string, password string) *Request
- func (r *Request) SetDefaultRetry() *Request
- func (r *Request) SetExpectRespStatus(httpStatus int) *Request
- func (r *Request) SetHeader(key string, value string) *Request
- func (r *Request) SetQueryMap(content map[string]string) *Request
- func (r *Request) SetQueryParam(key string, value string) *Request
- func (r *Request) SetRetry(maxRetry int, interval time.Duration, status []int, statusBegin int, ...) *Request
- func (r *Request) SetRetryConfig(config *RetryConfig) *Request
- type Result
- type RetryConfig
- type TraceLog
Constants ¶
View Source
const ( POST = "POST" GET = "GET" HEAD = "HEAD" PUT = "PUT" DELETE = "DELETE" PATCH = "PATCH" OPTIONS = "OPTIONS" TypeJSON = "json" TypeXML = "xml" TypeUrlencoded = "urlencoded" TypeForm = "form" TypeFormData = "form-data" TypeHTML = "html" TypeText = "text" TypeMultipart = "multipart" )
Variables ¶
View Source
var Types = map[string]string{ TypeJSON: "application/json", TypeXML: "application/xml", TypeForm: "application/x-www-form-urlencoded", TypeFormData: "application/x-www-form-urlencoded", TypeUrlencoded: "application/x-www-form-urlencoded", TypeHTML: "text/html", TypeText: "text/plain", TypeMultipart: "multipart/form-data", }
Functions ¶
func DefaultClient ¶
func SetDefaultClient ¶
Types ¶
type Request ¶
type Request struct {
Client *http.Client
Url string
Method string
Header http.Header
Cookies []*http.Cookie
FormData url.Values
QueryData url.Values
TargetType string
ForceType string
BasicAuth struct{ Username, Password string }
IsKeepAlive bool
ExpectRespStatus int
RetryCfg *RetryConfig
}
A Request is a object storing all request data for client.
func NewRequest ¶
Used to create a new Request object.
func (*Request) CustomMethod ¶
Just a wrapper to initialize Request instance by method string
func (*Request) DisableKeepAlive ¶
func (*Request) EnableKeepAlive ¶
func (*Request) SetBasicAuth ¶
func (*Request) SetDefaultRetry ¶
func (*Request) SetExpectRespStatus ¶
response set a http status of response which you expected
func (*Request) SetQueryMap ¶
Query
func (*Request) SetRetry ¶
func (r *Request) SetRetry(maxRetry int, interval time.Duration, status []int, statusBegin int, statusEnd int) *Request
retry
func (*Request) SetRetryConfig ¶
func (r *Request) SetRetryConfig(config *RetryConfig) *Request
type Result ¶
Click to show internal directories.
Click to hide internal directories.