Documentation ¶
Index ¶
- 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 Upload(ctx context.Context, reqURL string, form UploadForm, options ...Option) (*http.Response, error)
- type FormFileFunc
- type HTTPClient
- type Option
- type UploadField
- type UploadForm
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
func Do(ctx context.Context, method, reqURL string, body []byte, options ...Option) (*http.Response, error)
Do send an HTTP request and returns an HTTP response
func Post ¶
func Post(ctx context.Context, reqURL string, body []byte, options ...Option) (*http.Response, error)
Post issues a POST to the specified URL.
Types ¶
type FormFileFunc ¶
FormFileFunc writes file content to multipart writer.
type HTTPClient ¶
type HTTPClient interface { // Do send an HTTP request and returns an HTTP response. // Should use context to specify the timeout for request. Do(ctx context.Context, method, reqURL string, body []byte, options ...Option) (*http.Response, error) // Upload issues a UPLOAD to the specified URL. // Should use context to specify the timeout for request. Upload(ctx context.Context, reqURL string, form UploadForm, options ...Option) (*http.Response, error) }
HTTPClient is the interface for a http client.
func NewHTTPClient ¶
func NewHTTPClient(client *http.Client) HTTPClient
NewHTTPClient returns a new http client
type Option ¶
type Option func(s *config)
Option configures how we set up the http request.
func WithClose ¶
func WithClose() Option
WithClose specifies close the connection after replying to this request (for servers) or after sending this request and reading its response (for clients).
func WithCookies ¶
WithCookies specifies the cookies to http request.
func WithHeader ¶
WithHeader specifies the header to http request.
type UploadField ¶
type UploadField func(f *uploadForm)
UploadField configures how we set up the upload from.
func WithFormField ¶
func WithFormField(fieldName, fieldValue string) UploadField
WithFormField specifies the form field to upload from.
func WithFormFile ¶
func WithFormFile(fieldName, fileName string, fn FormFileFunc) UploadField
WithFormFile specifies the file field to upload from.
type UploadForm ¶
type UploadForm interface { // Write writes fields to multipart writer Write(w *multipart.Writer) error }
UploadForm is the interface for http upload.
func NewUploadForm ¶
func NewUploadForm(fields ...UploadField) UploadForm
NewUploadForm returns an upload form