Documentation
¶
Index ¶
- type Client
- func (c *Client) Clone() *Client
- func (c *Client) Delete(url ...string) *Request
- func (c *Client) DevMode() *Client
- func (c *Client) DisableAllowGetMethodPayload() *Client
- func (c *Client) DisableDebug() *Client
- func (c *Client) DisableInsecureSkipVerify() *Client
- func (c *Client) EnableAllowGetMethodPayload() *Client
- func (c *Client) EnableDebug() *Client
- func (c *Client) EnableInsecureSkipVerify() *Client
- func (c *Client) Get(url ...string) *Request
- func (c *Client) GetClient() *http.Client
- func (c *Client) GetTLSClientConfig() *tls.Config
- func (c *Client) Head(url ...string) *Request
- func (c *Client) Http() *Request
- func (c *Client) OnAfterResponse(middleware ResponseMiddleware) *Client
- func (c *Client) OnBeforeRequest(middleware RequestMiddleware) *Client
- func (c *Client) OnError(handler ErrorHook) *Client
- func (c *Client) Options(url ...string) *Request
- func (c *Client) Patch(url ...string) *Request
- func (c *Client) Post(url ...string) *Request
- func (c *Client) Put(url ...string) *Request
- func (c *Client) SetBaseURL(baseURL string) *Client
- func (c *Client) SetCommonCookies(cookies ...*http.Cookie) *Client
- func (c *Client) SetCommonErrorResult(err interface{}) *Client
- func (c *Client) SetCommonFormData(data map[string]string) *Client
- func (c *Client) SetCommonHeader(key, value string) *Client
- func (c *Client) SetCommonHeaders(headers map[string]string) *Client
- func (c *Client) SetCommonPathParam(key, value string) *Client
- func (c *Client) SetCommonPathParams(params map[string]string) *Client
- func (c *Client) SetCommonQueryParam(key, value string) *Client
- func (c *Client) SetCommonQueryParams(params map[string]string) *Client
- func (c *Client) SetContext(ctx context.Context) *Client
- func (c *Client) SetJSONMarshal(fn func(v interface{}) ([]byte, error)) *Client
- func (c *Client) SetJSONUnmarshal(fn func(data []byte, v interface{}) error) *Client
- func (c *Client) SetProxy(proxy func(*http.Request) (*url.URL, error)) *Client
- func (c *Client) SetResultStateCheckFunc(fn func(*Response) ResultState) *Client
- func (c *Client) SetRetryCondition(condition RetryConditionFunc) *Client
- func (c *Client) SetRetryCount(count int) *Client
- func (c *Client) SetRetryInterval(interval time.Duration) *Client
- func (c *Client) SetTLSClientConfig(config *tls.Config) *Client
- func (c *Client) SetTimeout(timeout time.Duration) *Client
- func (c *Client) SetUserAgent(userAgent string) *Client
- func (c *Client) SetXMLMarshal(fn func(v interface{}) ([]byte, error)) *Client
- func (c *Client) SetXMLUnmarshal(fn func(data []byte, v interface{}) error) *Client
- type Config
- type ErrorHook
- type Request
- func (r *Request) Clone() *Request
- func (r *Request) Context() context.Context
- func (r *Request) Delete(url ...string) (*Response, error)
- func (r *Request) Do() (*Response, error)
- func (r *Request) Execute() (*Response, error)
- func (r *Request) Get(url ...string) (*Response, error)
- func (r *Request) Head(url ...string) (*Response, error)
- func (r *Request) Header() http.Header
- func (r *Request) Method() string
- func (r *Request) MustDelete(url ...string) *Response
- func (r *Request) MustExecute() *Response
- func (r *Request) MustGet(url ...string) *Response
- func (r *Request) MustHead(url ...string) *Response
- func (r *Request) MustOptions(url ...string) *Response
- func (r *Request) MustPatch(url ...string) *Response
- func (r *Request) MustPost(url ...string) *Response
- func (r *Request) MustPut(url ...string) *Response
- func (r *Request) Options(url ...string) (*Response, error)
- func (r *Request) Patch(url ...string) (*Response, error)
- func (r *Request) Post(url ...string) (*Response, error)
- func (r *Request) Put(url ...string) (*Response, error)
- func (r *Request) Send() (*Response, error)
- func (r *Request) SetAuthToken(token string) *Request
- func (r *Request) SetBasicAuth(username, password string) *Request
- func (r *Request) SetBearerToken(token string) *Request
- func (r *Request) SetBody(body interface{}) *Request
- func (r *Request) SetBodyBytes(body []byte) *Request
- func (r *Request) SetBodyJSON(body interface{}) *Request
- func (r *Request) SetBodyReader(body io.Reader) *Request
- func (r *Request) SetBodyString(body string) *Request
- func (r *Request) SetBodyXML(body interface{}) *Request
- func (r *Request) SetContext(ctx context.Context) *Request
- func (r *Request) SetCookie(cookie *http.Cookie) *Request
- func (r *Request) SetCookies(cookies ...*http.Cookie) *Request
- func (r *Request) SetError(result interface{}) *Request
- func (r *Request) SetErrorResult(result interface{}) *Request
- func (r *Request) SetFormData(data map[string]string) *Request
- func (r *Request) SetFormDataFromValues(data url.Values) *Request
- func (r *Request) SetHeader(key, value string) *Request
- func (r *Request) SetHeaderVerbatim(key, value string) *Request
- func (r *Request) SetHeaders(headers map[string]string) *Request
- func (r *Request) SetOutput(filePath string) *Request
- func (r *Request) SetPathParam(key, value string) *Request
- func (r *Request) SetPathParams(params map[string]string) *Request
- func (r *Request) SetQueryParam(key, value string) *Request
- func (r *Request) SetQueryParams(params map[string]string) *Request
- func (r *Request) SetQueryParamsFromValues(params url.Values) *Request
- func (r *Request) SetQueryString(query string) *Request
- func (r *Request) SetResult(result interface{}) *Request
- func (r *Request) SetSuccessResult(result interface{}) *Request
- func (r *Request) SetTracer(tracer trace.Tracer, spanName string) *Request
- func (r *Request) SetUploadCallback(callback func(written int64, total int64)) *Request
- func (r *Request) SetUserAgent(userAgent string) *Request
- func (r *Request) String() string
- func (r *Request) URL() string
- func (r *Request) Validate() error
- type RequestMiddleware
- type Response
- func (r *Response) Body() []byte
- func (r *Response) ContentType() string
- func (r *Response) Cookies() []*http.Cookie
- func (r *Response) Duration() time.Duration
- func (r *Response) Error() error
- func (r *Response) IsError() bool
- func (r *Response) IsHTML() bool
- func (r *Response) IsJSON() bool
- func (r *Response) IsSuccess() bool
- func (r *Response) IsText() bool
- func (r *Response) IsXML() bool
- func (r *Response) JSON(v interface{}) error
- func (r *Response) Location() string
- func (r *Response) ResultState() ResultState
- func (r *Response) Size() int64
- func (r *Response) String() string
- func (r *Response) Time() time.Time
- func (r *Response) XML(v interface{}) error
- type ResponseMiddleware
- type ResultState
- type RetryConditionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an HTTP client with chainable methods
func NewClientWithConfig ¶
NewClientWithConfig creates a new HTTP client with provided configuration
func (*Client) DisableAllowGetMethodPayload ¶
DisableAllowGetMethodPayload disallows GET requests to have a body
func (*Client) DisableDebug ¶
DisableDebug disables debug mode
func (*Client) DisableInsecureSkipVerify ¶
DisableInsecureSkipVerify disables skipping TLS certificate verification
func (*Client) EnableAllowGetMethodPayload ¶
EnableAllowGetMethodPayload allows GET requests to have a body
func (*Client) EnableInsecureSkipVerify ¶
EnableInsecureSkipVerify enables skipping TLS certificate verification
func (*Client) GetTLSClientConfig ¶
GetTLSClientConfig returns the TLS configuration
func (*Client) OnAfterResponse ¶
func (c *Client) OnAfterResponse(middleware ResponseMiddleware) *Client
OnAfterResponse adds a middleware that runs after receiving the response
func (*Client) OnBeforeRequest ¶
func (c *Client) OnBeforeRequest(middleware RequestMiddleware) *Client
OnBeforeRequest adds a middleware that runs before sending the request
func (*Client) SetBaseURL ¶
SetBaseURL sets the base URL for the client
func (*Client) SetCommonCookies ¶
SetCommonCookies sets cookies that will be added to all requests
func (*Client) SetCommonErrorResult ¶
SetCommonErrorResult sets the common error result type
func (*Client) SetCommonFormData ¶
SetCommonFormData sets form data that will be added to all requests
func (*Client) SetCommonHeader ¶
SetCommonHeader sets a header that will be added to all requests
func (*Client) SetCommonHeaders ¶
SetCommonHeaders sets multiple headers from a map
func (*Client) SetCommonPathParam ¶
SetCommonPathParam sets a path parameter that will be used for URL replacement
func (*Client) SetCommonPathParams ¶
SetCommonPathParams sets multiple path parameters from a map
func (*Client) SetCommonQueryParam ¶
SetCommonQueryParam sets a query parameter that will be added to all requests
func (*Client) SetCommonQueryParams ¶
SetCommonQueryParams sets multiple query parameters from a map
func (*Client) SetContext ¶
SetContext sets the default context for all requests created from this client
func (*Client) SetJSONMarshal ¶
SetJSONMarshal sets the JSON marshal function
func (*Client) SetJSONUnmarshal ¶
SetJSONUnmarshal sets the JSON unmarshal function
func (*Client) SetResultStateCheckFunc ¶
func (c *Client) SetResultStateCheckFunc(fn func(*Response) ResultState) *Client
SetResultStateCheckFunc sets the function to check result state
func (*Client) SetRetryCondition ¶
func (c *Client) SetRetryCondition(condition RetryConditionFunc) *Client
SetRetryCondition sets the condition for when to retry
func (*Client) SetRetryCount ¶
SetRetryCount sets the number of retry attempts
func (*Client) SetRetryInterval ¶
SetRetryInterval sets the interval between retries
func (*Client) SetTLSClientConfig ¶
SetTLSClientConfig sets the TLS configuration
func (*Client) SetTimeout ¶
SetTimeout sets the request timeout
func (*Client) SetUserAgent ¶
SetUserAgent sets the User-Agent header for all requests
func (*Client) SetXMLMarshal ¶
SetXMLMarshal sets the XML marshal function
type Config ¶
type Config struct {
BaseURL string
Timeout time.Duration
Headers map[string]string
QueryParams map[string]string
PathParams map[string]string
UserAgent string
Debug bool
AllowGetPayload bool
RetryCount int
RetryInterval time.Duration
TLSConfig *tls.Config
Transport http.RoundTripper
BeforeRequest []RequestMiddleware
AfterResponse []ResponseMiddleware
RetryCondition RetryConditionFunc
ErrorHandler ErrorHook
OnError ErrorHook
CommonErrorResult interface{}
ResultChecker func(*Response) ResultState
}
Config holds default configuration for Client
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request represents an HTTP request
func (*Request) MustDelete ¶
MustDelete executes a DELETE request and panics on error
func (*Request) MustExecute ¶
MustExecute executes the request and panics on error
func (*Request) MustOptions ¶
MustOptions executes an OPTIONS request and panics on error
func (*Request) SetAuthToken ¶
SetAuthToken is an alias for SetBearerToken
func (*Request) SetBasicAuth ¶
SetBasicAuth sets basic authentication
func (*Request) SetBearerToken ¶
SetBearerToken sets the bearer token for authentication
func (*Request) SetBodyBytes ¶
SetBodyBytes sets the request body from bytes
func (*Request) SetBodyJSON ¶
SetBodyJSON sets the request body as JSON
func (*Request) SetBodyReader ¶
SetBodyReader sets the request body from an io.Reader
func (*Request) SetBodyString ¶
SetBodyString sets the request body from a string
func (*Request) SetBodyXML ¶
SetBodyXML sets the request body as XML
func (*Request) SetContext ¶
SetContext sets the context for the request
func (*Request) SetCookies ¶
SetCookies sets cookies for the request
func (*Request) SetErrorResult ¶
SetErrorResult sets the struct to unmarshal error response into
func (*Request) SetFormData ¶
SetFormData sets form data for the request
func (*Request) SetFormDataFromValues ¶
SetFormDataFromValues sets form data from url.Values
func (*Request) SetHeaderVerbatim ¶
SetHeaderVerbatim sets a header without canonicalizing the key
func (*Request) SetHeaders ¶
SetHeaders sets multiple headers from a map
func (*Request) SetPathParam ¶
SetPathParam sets a path parameter for URL replacement
func (*Request) SetPathParams ¶
SetPathParams sets multiple path parameters from a map
func (*Request) SetQueryParam ¶
SetQueryParam sets a query parameter for the request
func (*Request) SetQueryParams ¶
SetQueryParams sets multiple query parameters from a map
func (*Request) SetQueryParamsFromValues ¶
SetQueryParamsFromValues sets query parameters from url.Values
func (*Request) SetQueryString ¶
SetQueryString sets the query string directly
func (*Request) SetSuccessResult ¶
SetSuccessResult sets the struct to unmarshal successful response into
func (*Request) SetUploadCallback ¶
SetUploadCallback sets a callback function for upload progress
func (*Request) SetUserAgent ¶
SetUserAgent sets the User-Agent header for this specific request
type RequestMiddleware ¶
RequestMiddleware defines a function that can modify a request before it's sent
type Response ¶
type Response struct {
Request *Request
Response *http.Response
Err error
// Embedded from http.Response for direct access
Status string
StatusCode int
Proto string
ProtoMajor int
ProtoMinor int
Header http.Header
// contains filtered or unexported fields
}
Response represents an HTTP response
func (*Response) ContentType ¶
ContentType returns the Content-Type header value
func (*Response) IsError ¶
IsError returns true if the response is an error (4xx or 5xx status code)
func (*Response) ResultState ¶
func (r *Response) ResultState() ResultState
ResultState returns the state of the response
type ResponseMiddleware ¶
ResponseMiddleware defines a function that can modify a response after it's received
type ResultState ¶
type ResultState int
ResultState represents the state of the response
const ( SuccessState ResultState = iota ErrorState UnknownState )
type RetryConditionFunc ¶
RetryConditionFunc defines when a request should be retried