Documentation ¶
Index ¶
- Constants
- Variables
- func IsStatusErr(e error) bool
- func SetDefault(c *Client)
- type BaseHook
- type CallOptions
- func (o *CallOptions) AddAuthorization(auth string)
- func (o *CallOptions) AddBasicAuth(username, password string)
- func (o *CallOptions) AddBearAuth(auth string)
- func (o *CallOptions) AddCookie(cookie *http.Cookie)
- func (o *CallOptions) AddHeader(key string, value interface{})
- func (o *CallOptions) AddParam(key string, value string)
- func (o *CallOptions) AddQuery(key string, value interface{})
- func (o *CallOptions) AddXAuthToken(token string)
- func (o *CallOptions) AddXJwtToken(token string)
- type Client
- func (c *Client) Connect(ctx context.Context, url string, opts ...*CallOptions) *Response
- func (c *Client) Delete(ctx context.Context, url string, opts ...*CallOptions) *Response
- func (c *Client) Get(ctx context.Context, url string, opts ...*CallOptions) *Response
- func (c *Client) Head(ctx context.Context, url string, opts ...*CallOptions) *Response
- func (c *Client) Options(ctx context.Context, url string, opts ...*CallOptions) *Response
- func (c *Client) Patch(ctx context.Context, url string, reqBody interface{}, opts ...*CallOptions) *Response
- func (c *Client) Post(ctx context.Context, url string, reqBody interface{}, opts ...*CallOptions) *Response
- func (c *Client) Put(ctx context.Context, url string, reqBody interface{}, opts ...*CallOptions) *Response
- func (c *Client) Trace(ctx context.Context, url string, opts ...*CallOptions) *Response
- type Config
- type Hook
- type Response
- func Connect(ctx context.Context, url string, opts ...*CallOptions) *Response
- func Delete(ctx context.Context, url string, opts ...*CallOptions) *Response
- func Get(ctx context.Context, url string, opts ...*CallOptions) *Response
- func Head(ctx context.Context, url string, opts ...*CallOptions) *Response
- func Options(ctx context.Context, url string, opts ...*CallOptions) *Response
- func Patch(ctx context.Context, url string, reqBody interface{}, opts ...*CallOptions) *Response
- func Post(ctx context.Context, url string, reqBody interface{}, opts ...*CallOptions) *Response
- func Put(ctx context.Context, url string, reqBody interface{}, opts ...*CallOptions) *Response
- func Trace(ctx context.Context, url string, opts ...*CallOptions) *Response
- type StatusErr
Constants ¶
View Source
const ( TypeJSON = "application/json" TypeXML = "application/xml" TypeForm = "application/x-www-form-urlencoded" TypeHTML = "text/html" TypeText = "text/plain" )
预定义常见类型
View Source
const (
CharsetUTF8 = "UTF-8"
)
Variables ¶
View Source
var ( ErrNoData = errors.New("httpc: no data") ErrNotSupport = errors.New("httpc: not support") ErrInvalidType = errors.New("httpc: invalid type") )
some erorrs
Functions ¶
Types ¶
type CallOptions ¶
type CallOptions struct { BaseUrl string // 默认url地址 ContentType string // 编码格式,默认application/json Charset string // 编码格式,默认空,若非空则与contentType拼接到一起,比如 text/plain;charset=UTF-8 Params map[string]string // path中参数,例如: http://www.baidu.com/im/v1/chats/:chat_id Query url.Values // query参数,例如:http://www.baidu.com?aa=xxx&bb=xxx Header http.Header // 消息头 Cookies []*http.Cookie // Retry int // 重试次数 Hook Hook // 回调函数 }
func (*CallOptions) AddAuthorization ¶
func (o *CallOptions) AddAuthorization(auth string)
func (*CallOptions) AddBasicAuth ¶
func (o *CallOptions) AddBasicAuth(username, password string)
func (*CallOptions) AddBearAuth ¶
func (o *CallOptions) AddBearAuth(auth string)
func (*CallOptions) AddCookie ¶
func (o *CallOptions) AddCookie(cookie *http.Cookie)
func (*CallOptions) AddHeader ¶
func (o *CallOptions) AddHeader(key string, value interface{})
func (*CallOptions) AddParam ¶
func (o *CallOptions) AddParam(key string, value string)
func (*CallOptions) AddQuery ¶
func (o *CallOptions) AddQuery(key string, value interface{})
func (*CallOptions) AddXAuthToken ¶
func (o *CallOptions) AddXAuthToken(token string)
func (*CallOptions) AddXJwtToken ¶
func (o *CallOptions) AddXJwtToken(token string)
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client 简单封装http client,方便调用,注意,CallOptions最多只能传1个
1: 构建Request 2: body编解码 3: retry 4: hook 5: rsp wrapper
type Config ¶
type Config struct { Timeout time.Duration DialTimeout time.Duration HandshakeTimeout time.Duration KeepAlive time.Duration BaseUrl string }
Config .
type Hook ¶
type Hook interface { OnRequest(ctx context.Context, req *http.Request) error OnResponse(ctx context.Context, rsp *http.Response) error OnError(ctx context.Context, err error) }
Hook 回调函数,可增加签名等通用处理
type Response ¶
func Patch ¶
func Patch(ctx context.Context, url string, reqBody interface{}, opts ...*CallOptions) *Response
func Post ¶
func Post(ctx context.Context, url string, reqBody interface{}, opts ...*CallOptions) *Response
Click to show internal directories.
Click to hide internal directories.