Documentation
¶
Index ¶
- func DefaultTransport() *http.Transport
- func FormPatch(ctx context.Context, url string, fields map[string]string, files []FormFile, ...) (int, []byte, error)
- func FormPost(ctx context.Context, url string, fields map[string]string, files []FormFile, ...) (int, []byte, error)
- func FormPut(ctx context.Context, url string, fields map[string]string, files []FormFile, ...) (int, []byte, error)
- func JSONDelete(ctx context.Context, url string, headers map[string]string) (int, []byte, error)
- func JSONGet(ctx context.Context, url string, headers map[string]string) (int, []byte, error)
- func JSONHead(ctx context.Context, url string, headers map[string]string) (int, []byte, error)
- func JSONOptions(ctx context.Context, url string, headers map[string]string) (int, []byte, error)
- func JSONPatch(ctx context.Context, url string, body any, headers map[string]string) (int, []byte, error)
- func JSONPost(ctx context.Context, url string, body any, headers map[string]string) (int, []byte, error)
- func JSONPut(ctx context.Context, url string, body any, headers map[string]string) (int, []byte, error)
- func NewClient(client *http.Client) *http.Client
- func SendFormRequest(ctx context.Context, method, url string, fields map[string]string, ...) (int, []byte, error)
- func SendRequest(ctx context.Context, method, url string, body any, headers map[string]string) (int, []byte, error)
- func SetDefaultClient(client *http.Client)
- type FormFile
- type HTTPClient
- func (hc *HTTPClient) FormPatch(ctx context.Context, url string, fields map[string]string, files []FormFile, ...) (int, []byte, error)
- func (hc *HTTPClient) FormPost(ctx context.Context, url string, fields map[string]string, files []FormFile, ...) (int, []byte, error)
- func (hc *HTTPClient) FormPut(ctx context.Context, url string, fields map[string]string, files []FormFile, ...) (int, []byte, error)
- func (hc *HTTPClient) JSONDelete(ctx context.Context, url string, headers map[string]string) (int, []byte, error)
- func (hc *HTTPClient) JSONGet(ctx context.Context, url string, headers map[string]string) (int, []byte, error)
- func (hc *HTTPClient) JSONHead(ctx context.Context, url string, headers map[string]string) (int, []byte, error)
- func (hc *HTTPClient) JSONOptions(ctx context.Context, url string, headers map[string]string) (int, []byte, error)
- func (hc *HTTPClient) JSONPatch(ctx context.Context, url string, body any, headers map[string]string) (int, []byte, error)
- func (hc *HTTPClient) JSONPost(ctx context.Context, url string, body any, headers map[string]string) (int, []byte, error)
- func (hc *HTTPClient) JSONPut(ctx context.Context, url string, body any, headers map[string]string) (int, []byte, error)
- func (hc *HTTPClient) SendFormRequest(ctx context.Context, method, url string, fields map[string]string, ...) (int, []byte, error)
- func (hc *HTTPClient) SendRequest(ctx context.Context, method, url string, body any, headers map[string]string) (int, []byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultTransport ¶
DefaultTransport returns a new *http.Transport with all default settings. Use this when wrapping the transport in a custom RoundTripper while keeping the baseline configuration:
client := &http.Client{
Transport: myLoggingRoundTripper{next: httpclient.DefaultTransport()},
}
func FormPatch ¶ added in v0.0.11
func FormPatch(ctx context.Context, url string, fields map[string]string, files []FormFile, headers map[string]string) (int, []byte, error)
FormPatch sends a multipart/form-data PATCH request using the package-level default client.
func FormPost ¶ added in v0.0.11
func FormPost(ctx context.Context, url string, fields map[string]string, files []FormFile, headers map[string]string) (int, []byte, error)
FormPost sends a multipart/form-data POST request using the package-level default client. fields contains plain text form fields; files contains file uploads. Either may be nil.
func FormPut ¶ added in v0.0.11
func FormPut(ctx context.Context, url string, fields map[string]string, files []FormFile, headers map[string]string) (int, []byte, error)
FormPut sends a multipart/form-data PUT request using the package-level default client.
func JSONDelete ¶
func JSONOptions ¶
func NewClient ¶
NewClient populates zero/nil fields in client with production-ready defaults and returns it. Pass nil to get a fully-defaulted client.
Transport handling:
- nil Transport → a new *http.Transport is created (ForceAttemptHTTP2=true).
- *http.Transport → only zero-value duration/size fields are filled; boolean fields are left untouched so explicit caller choices are kept.
- other RoundTripper → used as-is.
func SendFormRequest ¶ added in v0.0.11
func SendFormRequest(ctx context.Context, method, url string, fields map[string]string, files []FormFile, headers map[string]string) (int, []byte, error)
SendFormRequest executes a multipart/form-data request using the package-level default client. ctx controls cancellation and deadlines; pass context.Background() when no deadline propagation is needed.
func SendRequest ¶
func SendRequest(ctx context.Context, method, url string, body any, headers map[string]string) (int, []byte, error)
SendRequest executes an HTTP request using the package-level default client. ctx controls cancellation and deadlines; pass context.Background() when no deadline propagation is needed.
func SetDefaultClient ¶
SetDefaultClient replaces the package-level client used by SendRequest and all JSON* convenience functions. It is safe to call concurrently. Pass nil to reset to the built-in defaults.
Prefer creating an *HTTPClient instance (NewHTTPClient) over replacing the global when different parts of your application need different settings.
Types ¶
type FormFile ¶ added in v0.0.11
type FormFile struct {
FieldName string // form field name (e.g. "avatar")
FileName string // file name sent to the server (e.g. "photo.png")
Content io.Reader // file content
}
FormFile represents a file to include in a multipart/form-data request.
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient wraps an *http.Client and mirrors the package-level API. Use this when different parts of your application need separate clients (e.g. different timeouts or TLS config) rather than sharing the global.
c := httpclient.NewHTTPClient(&http.Client{Timeout: 5 * time.Minute})
status, body, err := c.JSONPost(ctx, url, payload, nil)
func NewHTTPClient ¶
func NewHTTPClient(client *http.Client) *HTTPClient
NewHTTPClient wraps client with production defaults applied via NewClient. Pass nil to start from all defaults.
func (*HTTPClient) JSONDelete ¶
func (*HTTPClient) JSONOptions ¶
func (*HTTPClient) SendFormRequest ¶ added in v0.0.11
func (hc *HTTPClient) SendFormRequest(ctx context.Context, method, url string, fields map[string]string, files []FormFile, headers map[string]string) (int, []byte, error)
SendFormRequest executes a multipart/form-data request using this instance's client.
func (*HTTPClient) SendRequest ¶
func (hc *HTTPClient) SendRequest(ctx context.Context, method, url string, body any, headers map[string]string) (int, []byte, error)
SendRequest executes an HTTP request using this instance's client. ctx controls cancellation and deadlines; pass context.Background() when no deadline propagation is needed.