Documentation ¶
Index ¶
- Constants
- Variables
- func MapToJsonString(m J) (string, error)
- func MapToQueryString(m KV) string
- type AfterResponseHookFunction
- type BeforeRequestHookFunction
- type F
- type Files
- type J
- type KV
- type L
- type P
- type Response
- func Delete(url string, params *P) (*Response, error)
- func Get(url string, params *P) (*Response, error)
- func Head(url string, params *P) (*Response, error)
- func Options(url string, params *P) (*Response, error)
- func Post(url string, params *P) (*Response, error)
- func Put(url string, params *P) (*Response, error)
- func Request(url string, params *P) (*Response, error)
- type Session
- func (s *Session) Delete(url string, params *P) (*Response, error)
- func (s *Session) Get(url string, params *P) (*Response, error)
- func (s *Session) Head(url string, params *P) (*Response, error)
- func (s *Session) Options(url string, params *P) (*Response, error)
- func (s *Session) Patch(url string, params *P) (*Response, error)
- func (s *Session) Post(url string, params *P) (*Response, error)
- func (s *Session) Put(url string, params *P) (*Response, error)
- func (s *Session) RegisterAfterResponseHook(fn AfterResponseHookFunction) (int, error)
- func (s *Session) RegisterBeforeRequestHook(fn BeforeRequestHookFunction) (int, error)
- func (session *Session) Request(url string, p *P) (*Response, error)
- func (s *Session) ResetAfterResponseHook()
- func (s *Session) ResetBeforeRequestHook()
- func (s *Session) UnregisterAfterResponseHook(index int) error
- func (s *Session) UnregisterBeforeRequestHook(index int) error
Constants ¶
View Source
const ( GET = "GET" POST = "POST" PUT = "PUT" DELETE = "DELETE" OPTIONS = "OPTIONS" HEAD = "HEAD" PATCH = "PATCH" )
Variables ¶
View Source
var ( // ErrHookFuncMaxLimit will be throwed when the number of hook functions // more than MaxLimit = 8 ErrHookFuncMaxLimit = errors.New("HOOK函数数量要少于8个") // ErrIndexOutofBound means the index out of bound ErrIndexOutOfBound = errors.New("Index超出") )
Functions ¶
func MapToJsonString ¶
func MapToQueryString ¶
Types ¶
type AfterResponseHookFunction ¶ added in v1.0.0
type BeforeRequestHookFunction ¶ added in v1.0.0
type P ¶
type P struct { Method string Params KV Data KV DataString string Json J JsonString string Headers KV Cookies KV Files Files Form KV Proxies string NotAllowRedirects bool Timeout time.Duration Retry int MaxRetry int }
请求参数
type Response ¶
type Response struct { Content []byte StatusCode int Header http.Header Cookie KV OriginResponse *http.Response }
func (*Response) IOReadCloser ¶ added in v1.0.1
func (r *Response) IOReadCloser() io.ReadCloser
response body to io.ReadCloser
func (*Response) Json ¶
To Struct response text like {"status": "1", "state": "success", "data": [{"value": 7396}, {"value": 5018}]}
type vv struct { Value int `json:"value"` } type rr struct { Status string `json:"status"` State string `json:"state"` Data []vv `json:"data"` }
var res rr _ := resp.Json(&res) fmt.Println(res)
To Map var res map[string]interface _ := resp.Json(&res) fmt.Println(res)
type Session ¶
type Session struct { Headers KV Cookies KV BaseUrl string Timeout time.Duration Proxies string MaxRetry int // contains filtered or unexported fields }
func NewSession ¶
func NewSession() *Session
func (*Session) RegisterAfterResponseHook ¶ added in v1.0.2
func (s *Session) RegisterAfterResponseHook(fn AfterResponseHookFunction) (int, error)
注册响应后的HOOK函数,返回注册成功的 index
func (*Session) RegisterBeforeRequestHook ¶ added in v1.0.2
func (s *Session) RegisterBeforeRequestHook(fn BeforeRequestHookFunction) (int, error)
注册请求前的HOOK函数,返回注册成功的 index
func (*Session) ResetAfterResponseHook ¶ added in v1.0.2
func (s *Session) ResetAfterResponseHook()
重置响应后的HOOK函数
func (*Session) ResetBeforeRequestHook ¶ added in v1.0.2
func (s *Session) ResetBeforeRequestHook()
重置请求前的HOOK函数
func (*Session) UnregisterAfterResponseHook ¶ added in v1.0.2
注销响应后的HOOK函数
func (*Session) UnregisterBeforeRequestHook ¶ added in v1.0.2
注销请求前的HOOK函数
Click to show internal directories.
Click to hide internal directories.