Documentation ¶
Index ¶
- Constants
- func Do(ctx context.Context, method, reqURL string, body []byte, options ...Option) (*http.Response, error)
- func Get(ctx context.Context, reqURL string, options ...Option) (*http.Response, error)
- func Post(ctx context.Context, reqURL string, body []byte, options ...Option) (*http.Response, error)
- func PostForm(ctx context.Context, reqURL string, data url.Values, options ...Option) (*http.Response, error)
- func PostJSON(ctx context.Context, reqURL string, body []byte, options ...Option) (*http.Response, error)
- func Upload(ctx context.Context, reqURL string, form UploadForm, options ...Option) (*http.Response, error)
- type Client
- type FormFileFunc
- type Option
- type UploadField
- type UploadForm
Constants ¶
View Source
const ( HeaderAccept = "Accept" HeaderAuthorization = "Authorization" HeaderContentType = "Content-Type" )
View Source
const ( ContentText = "text/plain;charset=utf-8" ContentJSON = "application/json;charset=utf-8" ContentForm = "application/x-www-form-urlencoded" ContentStream = "application/octet-stream" ContentFormMultipart = "multipart/form-data" )
View Source
const MaxFormMemory = 32 << 20
Variables ¶
This section is empty.
Functions ¶
func Do ¶
func Do(ctx context.Context, method, reqURL string, body []byte, options ...Option) (*http.Response, error)
Do 发送HTTP请求
func Post ¶
func Post(ctx context.Context, reqURL string, body []byte, options ...Option) (*http.Response, error)
Post 发送POST请求
func PostForm ¶
func PostForm(ctx context.Context, reqURL string, data url.Values, options ...Option) (*http.Response, error)
PostForm 发送POST表单请求
Types ¶
type Client ¶
type Client interface { // Do 发送HTTP请求 // 注意:应该使用Context设置请求超时时间 Do(ctx context.Context, method, reqURL string, body []byte, opts ...Option) (*http.Response, error) // Upload 上传文件 // 注意:应该使用Context设置请求超时时间 Upload(ctx context.Context, reqURL string, form UploadForm, opts ...Option) (*http.Response, error) }
Client HTTP客户端
func NewDefaultClient ¶
func NewDefaultClient(certs ...tls.Certificate) Client
NewDefaultClient 生成一个默认的HTTP客户端
func NewHTTPClient ¶
NewHTTPClient 通过官方 `http.Client` 生成一个HTTP客户端
type UploadField ¶
type UploadField func(form *uploadform)
UploadField 文件上传表单字段
func WithFormFile ¶
func WithFormFile(fieldname, filename string, fn FormFileFunc) UploadField
WithFormFile 设置表单文件字段
Click to show internal directories.
Click to hide internal directories.