Documentation ¶
Index ¶
- Constants
- type Cookie
- type IRequest
- type IResponse
- type MSI
- type MSS
- type Option
- type Request
- func (rq *Request) AddCookieSimple(k string, v interface{}) IRequest
- func (rq *Request) AddCookies(cookies ...*Cookie) IRequest
- func (rq *Request) AddData(k string, v interface{}) IRequest
- func (rq *Request) AddFile(field, filePath string) IRequest
- func (rq *Request) AddHeader(k string, v interface{}) IRequest
- func (rq *Request) AddParam(k string, v interface{}) IRequest
- func (rq *Request) DoGet() IResponse
- func (rq *Request) DoHttp() IResponse
- func (rq *Request) DoPost() IResponse
- func (rq *Request) DoPostFile() IResponse
- func (rq *Request) DoPostForm() IResponse
- func (rq *Request) Get(apiUrl string, param interface{}) IResponse
- func (rq *Request) ObjToJson(v interface{}) string
- func (rq *Request) Post(apiUrl string, data interface{}) IResponse
- func (rq *Request) PostForm(apiUrl string, formData interface{}) IResponse
- func (rq *Request) SetBaseUrl(baseUrl string) IRequest
- func (rq *Request) SetClient(c *http.Client) IRequest
- func (rq *Request) SetContentType(tp string) IRequest
- func (rq *Request) SetData(v interface{}) IRequest
- func (rq *Request) SetDebug(debug bool) IRequest
- func (rq *Request) SetFile(v interface{}) IRequest
- func (rq *Request) SetHeader(v interface{}) IRequest
- func (rq *Request) SetMethod(method string) IRequest
- func (rq *Request) SetOption(option *Option) IRequest
- func (rq *Request) SetParam(v interface{}) IRequest
- func (rq *Request) SetProxy(proxy string) IRequest
- func (rq *Request) SetRequest(r *http.Request) IRequest
- func (rq *Request) SetTimeOut(second int) IRequest
- func (rq *Request) SetTransport(transport *http.Transport) IRequest
- func (rq *Request) SetUrl(apiUrl string) IRequest
- func (rq *Request) SetUrlf(urlFormat string, v ...interface{}) IRequest
Constants ¶
View Source
const ( DURATION = time.Second DEFAULT_RESPONSE_TIME_OUT = DURATION * 5 // 默认超时时间 5s )
View Source
const ( GET = "GET" POST = "POST" DELETE = "DELETE" PUT = "PUT" HEAD = "HEAD" TRACE = "TRACE" OPTION = "OPTION" )
http method
View Source
const ( APPLICATION_JSON = "application/json" // json参数放body X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded" // 一般运用于表单提交 参数放body, & 拼接 FORM_DATA = "multipart/form-data" // 文件上传 参数放body, 参数用分隔符 -------- )
header value
View Source
const (
CONTENT_TYPE = "Content-Type"
)
header key
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IRequest ¶
type IRequest interface { SetDebug(debug bool) IRequest // 打印日志 SetBaseUrl(baseUrl string) IRequest // 这个会拼接在url前面 SetUrl(apiUrl string) IRequest // 设置Url SetUrlf(urlFormat string, v ...interface{}) IRequest // 格式化设置Url SetMethod(method string) IRequest // 设置请求方法 SetTimeOut(second int) IRequest // 设置超时时间 SetProxy(proxy string) IRequest // 设置代理 SetParam(v interface{}) IRequest // 设置url参数,? 后面的参数 SetHeader(v interface{}) IRequest // 设置头 SetData(v interface{}) IRequest // 设置body参数 SetFile(v interface{}) IRequest // 设置文件 AddCookies(cookies ...*Cookie) IRequest // 添加Cookie AddParam(k string, v interface{}) IRequest // 添加url参数,? 后面的参数 AddHeader(k string, v interface{}) IRequest // 添加头部参数 AddCookieSimple(k string, v interface{}) IRequest // 添加简单的cookie AddData(k string, v interface{}) IRequest // 添加body 参数 AddFile(field, filePath string) IRequest // 添加文件 SetContentType(tp string) IRequest // 设置 content-type SetTransport(transport *http.Transport) IRequest // 自定义transport SetRequest(r *http.Request) IRequest // 自定义请求体 SetClient(c *http.Client) IRequest // 自定义HTTP client SetOption(option *Option) IRequest // 自定义参数 Get(apiUrl string, param interface{}) IResponse // GET 请求 Post(apiUrl string, data interface{}) IResponse // POST 请求 PostForm(apiUrl string, formData interface{}) IResponse // POST FORM 请求 DoHttp() IResponse // 发起请求 DoPost() IResponse // 发起post请求 DoGet() IResponse // 发起get请求 DoPostForm() IResponse // 发起post form请求 DoPostFile() IResponse // 发起post multipart/form-data 请求 }
func NewRequest ¶
func NewRequest() IRequest
type IResponse ¶
type IResponse interface { GetRequest() *http.Request // 获取请求体 GetResponse() *http.Response // 获取响应体 GetBody() string // 获取body内容 GetStatus() int // 获取响应状态码 IsStatusOk() bool // 响应状态码 == 200 AssertStatus(status int) // 断言状态码 BodyUnmarshal(v interface{}) error // 数据解析 Then(func(resp *http.Response)) IResponse // 自定义处理 response Error() error // 返回请求错误 OnSuccess(func(resp IResponse)) IResponse // 成功回调 OnError(func(resp IResponse)) IResponse // 失败回调 BodyCompile(pattern string) []string // 正则匹配body Print() // 打印请求和响应 }
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func (*Request) AddCookieSimple ¶
func (*Request) AddCookies ¶
func (*Request) DoPostFile ¶ added in v1.2.0
func (*Request) DoPostForm ¶
func (*Request) SetBaseUrl ¶
func (*Request) SetContentType ¶ added in v1.2.0
设置 content-type
func (*Request) SetTimeOut ¶
设置超时时间,超时包括连接时间,任何重定向和读取响应正文,0表示不会超时
func (*Request) SetTransport ¶
设置 Transport
Source Files ¶
Click to show internal directories.
Click to hide internal directories.