Documentation ¶
Index ¶
- Constants
- func Load(opts ...Option)
- func NewFormPayload(data map[string]interface{}) *formPayload
- func NewJSONPayload(data interface{}) *jsonPayload
- func NewKVParam(key string, value interface{}) *kvParam
- func NewMapParams(m map[string]interface{}) *mapParams
- func NewQueryParam(query string) *queryParam
- func NewWWWFormPayload(data map[string]interface{}) *wwwFormPayload
- type Header
- type HiHTTP
- type Option
- type Options
- type Param
- type Payload
- type Request
- func (r *Request) AddHeader(key, value string) *Request
- func (r *Request) Delete(ctx context.Context, urlStr string, data ...Param) (*Response, error)
- func (r *Request) Get(ctx context.Context, urlStr string, data ...Param) (*Response, error)
- func (r *Request) Patch(ctx context.Context, urlStr string, p Payload) (*Response, error)
- func (r *Request) Post(ctx context.Context, urlStr string, p Payload) (*Response, error)
- func (r *Request) Put(ctx context.Context, urlStr string, p Payload) (*Response, error)
- func (r *Request) SetCookies(hc ...*http.Cookie) *Request
- func (r *Request) SetHeader(key, value string) *Request
- func (r *Request) SetHeaders(headers Header) *Request
- type Response
- type RetryErrorFunc
Constants ¶
View Source
const ( // MethodGet HTTP method GET = "GET" // MethodPost HTTP method POST = "POST" // MethodPut HTTP method PUT = "PUT" // MethodDelete HTTP method DELETE = "DELETE" // MethodDelete HTTP method PATCH = "PATCH" )
View Source
const ( SerializationType string = "Content-Type" // SerializationTypeFormData 常见在表单的文件上传 SerializationTypeFormData string = "multipart/form-data" SerializationTypeJSON string = "application/json" SerializationTypeWWWFrom string = "application/x-www-form-urlencoded" // SerializationTypePlainText 用于请求和响应文本数据。 SerializationTypePlainText string = "text/plain; charset=utf-8" // SerializationTypeImageGIF gif图片 SerializationTypeImageGIF string = "image/gif" // SerializationTypeImageJPEG jpeg图片 SerializationTypeImageJPEG string = "image/jpeg" // SerializationTypeImagePNG png图片 SerializationTypeImagePNG string = "image/png" )
Variables ¶
This section is empty.
Functions ¶
func NewFormPayload ¶
func NewFormPayload(data map[string]interface{}) *formPayload
NewFormPayload 会根据序列化类型,生成一个payload Content-Type = multipart/form-data
func NewJSONPayload ¶
func NewJSONPayload(data interface{}) *jsonPayload
NewJSONPayload 会根据序列化类型,生成一个payload Content-Type = application/json
func NewKVParam ¶
func NewKVParam(key string, value interface{}) *kvParam
func NewMapParams ¶
func NewMapParams(m map[string]interface{}) *mapParams
func NewQueryParam ¶
func NewQueryParam(query string) *queryParam
func NewWWWFormPayload ¶
func NewWWWFormPayload(data map[string]interface{}) *wwwFormPayload
NewWWWFormPayload 会根据序列化类型,生成一个payload Content-Type = application/x-www-form-urlencoded
Types ¶
type Header ¶ added in v0.0.6
type HiHTTP ¶
type HiHTTP interface { Get(ctx context.Context, urlStr string, data ...Param) (*Response, error) Post(ctx context.Context, urlStr string, p Payload) (*Response, error) Put(ctx context.Context, urlStr string, p Payload) (*Response, error) Delete(ctx context.Context, urlStr string, data ...Param) (*Response, error) Patch(ctx context.Context, urlStr string, p Payload) (*Response, error) }
type Option ¶
type Option func(*Options)
func WithRetryCount ¶
func WithRetryError ¶
func WithRetryError(retryError RetryErrorFunc) Option
func WithRetryWait ¶
func WithTimeout ¶
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func (*Request) SetCookies ¶
SetCookies 设置cookie
func (*Request) SetHeaders ¶
SetHeaders 设置header参数 Header 例如: c.Headers(header)
type Response ¶ added in v0.0.6
type Response struct { Status string // e.g. "200 OK" StatusCode int // e.g. 200 Proto string // e.g. "HTTP/1.0" // ProtoMajor int // e.g. 1 // ProtoMinor int // e.g. 0 Header Header Body []byte // ContentLength int64 Close bool RequestDuration time.Duration }
func (*Response) BodyString ¶ added in v0.0.6
BodyString 直接返回一个string格式的body
Click to show internal directories.
Click to hide internal directories.