Documentation
¶
Index ¶
- Constants
- func DetectContentType(body any) string
- func IsEmptyString(str string) bool
- func Unmarshalc(c *Client, contentType string, b []byte, d interface{}) (err error)
- type Client
- func (c *Client) AddRetryAfterErrorCondition() *Client
- func (c *Client) AddRetryCondition(condition RetryConditionFunc) *Client
- func (c *Client) AddRetryHook(hook OnRetryFunc) *Client
- func (c *Client) DisableTrace() *Client
- func (c *Client) EnableTrace() *Client
- func (c *Client) GetHTTPClient() *http.Client
- func (c *Client) IsSetProxy() bool
- func (c *Client) NewRequest() *Request
- func (c *Client) OnAfterResponse(m ResponseMiddleware) *Client
- func (c *Client) OnBeforeRequest(m RequestMiddleware) *Client
- func (c *Client) OnError(h ErrorHook) *Client
- func (c *Client) OnRequestLog(rl RequestLogCallback) *Client
- func (c *Client) OnResponseLog(rl ResponseLogCallback) *Client
- func (c *Client) RemoveProxyURL() *Client
- func (c *Client) Req() *Request
- func (c *Client) SetAllowGetMethodPayload(a bool) *Client
- func (c *Client) SetAuthScheme(authScheme string) *Client
- func (c *Client) SetAuthToken(token string) *Client
- func (c *Client) SetBaseURL(url string) *Client
- func (c *Client) SetBasicAuth(username, password string) *Client
- func (c *Client) SetCertificates(certs ...tls.Certificate) *Client
- func (c *Client) SetCloseConnection(b bool) *Client
- func (c *Client) SetContentLength(b bool) *Client
- func (c *Client) SetCookie(cookie *http.Cookie) *Client
- func (c *Client) SetCookieJar(jar http.CookieJar) *Client
- func (c *Client) SetCookies(cookies []*http.Cookie) *Client
- func (c *Client) SetDebug(d bool) *Client
- func (c *Client) SetDebugBodySizeLimit(size int64) *Client
- func (c *Client) SetDisableWarn(d bool) *Client
- func (c *Client) SetDoNotParseResponse(b bool) *Client
- func (c *Client) SetError(err any) *Client
- func (c *Client) SetFormData(data map[string]string) *Client
- func (c *Client) SetHeader(key, value string) *Client
- func (c *Client) SetHeaderVerbatim(header, value string) *Client
- func (c *Client) SetHeaders(headers map[string]string) *Client
- func (c *Client) SetJSONEscapeHTML(b bool) *Client
- func (c *Client) SetLogger(l Logger) *Client
- func (c *Client) SetOutputDirectory(dir string) *Client
- func (c *Client) SetPathParam(key, value string) *Client
- func (c *Client) SetPathParams(params map[string]string) *Client
- func (c *Client) SetPreRequestHook(h PreRequestHook) *Client
- func (c *Client) SetProxyURL(proxyURL string) *Client
- func (c *Client) SetQueryParam(key, value string) *Client
- func (c *Client) SetQueryParams(params map[string]string) *Client
- func (c *Client) SetRedirectPolicy(policies ...RedirectPolicy) *Client
- func (c *Client) SetRetryAfter(callback RetryAfterFunc) *Client
- func (c *Client) SetRetryCount(count int) *Client
- func (c *Client) SetRetryMaxWaitTime(maxWaitTime time.Duration) *Client
- func (c *Client) SetRetryWaitTime(waitTime time.Duration) *Client
- func (c *Client) SetRootCertificate(pemFilePath string) *Client
- func (c *Client) SetRootCertificateFromString(pemContent string) *Client
- func (c *Client) SetScheme(scheme string) *Client
- func (c *Client) SetTLSClientConfig(config *tls.Config) *Client
- func (c *Client) SetTimeOut(timeout time.Duration) *Client
- func (c *Client) SetTransport(transport http.RoundTripper) *Client
- type ErrorHook
- type File
- type Logger
- type OnRetryFunc
- type Option
- type Options
- type PreRequestHook
- type RedirectPolicy
- type RedirectPolicyFunc
- type Request
- func (r *Request) AddRetryCondition(condition RetryConditionFunc) *Request
- func (r *Request) Context() context.Context
- func (r *Request) Delete(url string) (*Response, error)
- func (r *Request) DisableTrace() *Request
- func (r *Request) EnableTrace() *Request
- func (r *Request) Execute(method, url string) (*Response, error)
- func (r *Request) ExpectContentType(contentType string) *Request
- func (r *Request) ForceContentType(contentType string) *Request
- func (r *Request) Get(url string) (*Response, error)
- func (r *Request) GetTraceInfo() TraceInfo
- func (r *Request) Head(url string) (*Response, error)
- 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) SetAuthScheme(scheme string) *Request
- func (r *Request) SetAuthToken(token string) *Request
- func (r *Request) SetBasicAuth(username, password string) *Request
- func (r *Request) SetBody(body any) *Request
- func (r *Request) SetContentLength(b bool) *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) SetDoNotParseResponse(parse bool) *Request
- func (r *Request) SetError(err any) *Request
- func (r *Request) SetFile(param, filePath string) *Request
- func (r *Request) SetFileReader(field, fileName string, reader io.Reader) *Request
- func (r *Request) SetFiles(files map[string]string) *Request
- func (r *Request) SetFormData(data map[string]string) *Request
- func (r *Request) SetHeader(key, value string) *Request
- func (r *Request) SetHeaderMultiValues(headers map[string][]string) *Request
- func (r *Request) SetHeaderVerbatim(header, value string) *Request
- func (r *Request) SetHeaders(headers map[string]string) *Request
- func (r *Request) SetJSONEscapeHTML(b bool) *Request
- func (r *Request) SetOutput(file string) *Request
- func (r *Request) SetPathParam(param, 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) SetQueryString(query string) *Request
- func (r *Request) SetResult(res any) *Request
- func (r *Request) SetSRV(srv *SRVRecord) *Request
- type RequestLog
- type RequestLogCallback
- type RequestMiddleware
- type Response
- func (r *Response) Body() []byte
- func (r *Response) Cookies() []*http.Cookie
- func (r *Response) Cost() time.Duration
- func (r *Response) Error() any
- func (r *Response) Header() http.Header
- func (r *Response) IsError() bool
- func (r *Response) IsSuccess() bool
- func (r *Response) Proto() string
- func (r *Response) RawBody() io.ReadCloser
- func (r *Response) ReceivedAt() time.Time
- func (r *Response) Result() any
- func (r *Response) Size() int64
- func (r *Response) Status() string
- func (r *Response) StatusCode() int
- func (r *Response) String() string
- type ResponseLog
- type ResponseLogCallback
- type ResponseMiddleware
- type RetryAfterFunc
- type RetryConditionFunc
- type SRVRecord
- type TraceInfo
- type User
Constants ¶
const ( MethodGet = "GET" MethodPost = "POST" MethodPut = "PUT" MethodDelete = "DELETE" MethodHead = "HEAD" MethodOptions = "OPTIONS" MethodPatch = "PATCH" )
const Version = "0.1.0"
Version represents the released version.
Variables ¶
This section is empty.
Functions ¶
func DetectContentType ¶
func IsEmptyString ¶
Types ¶
type Client ¶
type Client struct { // Client level setting BaseURL string QueryParams url.Values FormData url.Values PathParams map[string]string Header http.Header UserInfo *User AuthScheme string Token string Cookies []*http.Cookie // HeaderAuthorizationKey is used to set request authorization header prefix. HeaderAuthorizationKey string // Error is used to return error message when http status code > 399. // It can be a pointer or non-pointer because it's going to convert internally by reflection. Error reflect.Type // Control flag Debug bool DisableWarn bool AllowGetMethodPayload bool // Retry strategy RetryCount int RetryWaitTime time.Duration RetryMaxWaitTime time.Duration RetryConditions []RetryConditionFunc RetryHooks []OnRetryFunc RetryAfter RetryAfterFunc // Http body encode and decode method JSONMarshal func(v any) ([]byte, error) JSONUnmarshal func(data []byte, v any) error XMLMarshal func(v any) ([]byte, error) XMLUnmarshal func(data []byte, v any) error // contains filtered or unexported fields }
Client is used to make http request and set client level settings. It provides an options to override request level settings.
func NewClientWithCookieJar ¶
func NewClientWithCookieJar() *Client
NewClientWithCookieJar creates a new client with cookie jar.
func NewWithClient ¶
NewWithClient creates a new client with given http.Client.
func NewWithLocalAddr ¶
NewWithLocalAddr creates a new client with given Local Address.
func (*Client) AddRetryAfterErrorCondition ¶
func (*Client) AddRetryCondition ¶
func (c *Client) AddRetryCondition(condition RetryConditionFunc) *Client
func (*Client) AddRetryHook ¶
func (c *Client) AddRetryHook(hook OnRetryFunc) *Client
func (*Client) DisableTrace ¶
func (*Client) EnableTrace ¶
func (*Client) GetHTTPClient ¶
func (*Client) IsSetProxy ¶
func (*Client) NewRequest ¶
func (*Client) OnAfterResponse ¶
func (c *Client) OnAfterResponse(m ResponseMiddleware) *Client
func (*Client) OnBeforeRequest ¶
func (c *Client) OnBeforeRequest(m RequestMiddleware) *Client
func (*Client) OnRequestLog ¶
func (c *Client) OnRequestLog(rl RequestLogCallback) *Client
func (*Client) OnResponseLog ¶
func (c *Client) OnResponseLog(rl ResponseLogCallback) *Client
func (*Client) RemoveProxyURL ¶
func (*Client) SetAllowGetMethodPayload ¶
func (*Client) SetAuthScheme ¶
SetAuthScheme method sets the auth scheme type in HTTP request. For Example: Authorization: <auth-scheme-value> <auth-token-value>
func (*Client) SetAuthToken ¶
func (*Client) SetBaseURL ¶
func (*Client) SetBasicAuth ¶
SetBasicAuth method sets the basic authentication header in HTTP request. For example: Authorization: Basic <base64-encoded-value>
func (*Client) SetCertificates ¶
func (c *Client) SetCertificates(certs ...tls.Certificate) *Client
func (*Client) SetCloseConnection ¶
func (*Client) SetContentLength ¶
func (*Client) SetDebugBodySizeLimit ¶
func (*Client) SetDisableWarn ¶
func (*Client) SetDoNotParseResponse ¶
func (*Client) SetHeaderVerbatim ¶
func (*Client) SetJSONEscapeHTML ¶
func (*Client) SetOutputDirectory ¶
func (*Client) SetPathParam ¶
func (*Client) SetPreRequestHook ¶
func (c *Client) SetPreRequestHook(h PreRequestHook) *Client
func (*Client) SetProxyURL ¶
func (*Client) SetQueryParam ¶
func (*Client) SetRedirectPolicy ¶
func (c *Client) SetRedirectPolicy(policies ...RedirectPolicy) *Client
func (*Client) SetRetryAfter ¶
func (c *Client) SetRetryAfter(callback RetryAfterFunc) *Client
func (*Client) SetRetryCount ¶
func (*Client) SetRetryMaxWaitTime ¶
func (*Client) SetRootCertificate ¶
func (*Client) SetRootCertificateFromString ¶
func (*Client) SetTransport ¶
func (c *Client) SetTransport(transport http.RoundTripper) *Client
type OnRetryFunc ¶
OnRetryFunc defines business logic in the retry process.
type Option ¶
type Option func(*Options)
func MaxWaitTime ¶
func RetryConditions ¶
func RetryConditions(conditions []RetryConditionFunc) Option
func RetryHooks ¶
func RetryHooks(hooks []OnRetryFunc) Option
type RedirectPolicy ¶
func DomainCheckRedirectPolicy ¶
func DomainCheckRedirectPolicy(hostnames ...string) RedirectPolicy
func FlexibleRedirectPolicy ¶
func FlexibleRedirectPolicy(num int) RedirectPolicy
func NoRedirectPolicy ¶
func NoRedirectPolicy() RedirectPolicy
type RedirectPolicyFunc ¶
type Request ¶
type Request struct { URL string Method string AuthScheme string Token string QueryParams url.Values FormData url.Values PathParams map[string]string Header http.Header Time time.Time Body any Result any Error any RawRequest *http.Request SRV *SRVRecord UserInfo *User Cookies []*http.Cookie Attempt int // contains filtered or unexported fields }
func (*Request) AddRetryCondition ¶
func (r *Request) AddRetryCondition(condition RetryConditionFunc) *Request
func (*Request) DisableTrace ¶
func (*Request) EnableTrace ¶
func (*Request) ExpectContentType ¶
func (*Request) ForceContentType ¶
func (*Request) GetTraceInfo ¶
func (*Request) SetAuthScheme ¶
func (*Request) SetAuthToken ¶
func (*Request) SetBasicAuth ¶
func (*Request) SetContentLength ¶
func (*Request) SetDoNotParseResponse ¶
func (*Request) SetFileReader ¶
func (*Request) SetHeaderMultiValues ¶
func (*Request) SetHeaderVerbatim ¶
func (*Request) SetJSONEscapeHTML ¶
func (*Request) SetPathParam ¶
func (*Request) SetQueryParam ¶
func (*Request) SetQueryParams ¶
func (*Request) SetQueryString ¶
type RequestLog ¶
type RequestLogCallback ¶
type RequestLogCallback func(*RequestLog) error
type RequestMiddleware ¶
type Response ¶
type Response struct { Request *Request RawResponse *http.Response // contains filtered or unexported fields }
func (*Response) RawBody ¶
func (r *Response) RawBody() io.ReadCloser
func (*Response) ReceivedAt ¶
func (*Response) StatusCode ¶
type ResponseLog ¶
type ResponseLogCallback ¶
type ResponseLogCallback func(*ResponseLog) error
type ResponseMiddleware ¶
type RetryAfterFunc ¶
RetryAfterFunc defines retry strategy, non-nil error returned if request is not retryable. Function result (0, nil) means using default algorithm.
type RetryConditionFunc ¶
RetryConditionFunc defines the conditions that trigger retry.
type TraceInfo ¶
type TraceInfo struct { DNSLookupCost time.Duration GetConnCost time.Duration TCPConnectionCost time.Duration TLSHandshakeCost time.Duration ServerProcessCost time.Duration ContentTransferCost time.Duration TotalCost time.Duration ConnReused bool ConnWasIdle bool ConnIdleTime time.Duration RequestAttempt int RemoteAddr net.Addr }