Documentation
¶
Index ¶
- Constants
- Variables
- func ContextWithLogger(ctx context.Context, logger Logger) context.Context
- func DefaultClient() *http.Client
- func DefaultPooledClient() *http.Client
- func DefaultPooledTransport() *http.Transport
- func DefaultTransport() *http.Transport
- func DrainBodyAndClose(response *http.Response) error
- func ExtractRequestIDFromContext(ctx context.Context) *string
- func ExtractRetryAttemptFromContext(ctx context.Context) int
- func GetBasicAuthHeaderValue(username, password string) string
- func GetTokenHeaderValue(token string) string
- func ThenDoNothing(_ *http.Response) error
- func ThenReturnDefaultError(r *http.Response) error
- type Client
- func (c *Client) AcceptJson() *Client
- func (c *Client) AuthBasic(username, password string) *Client
- func (c *Client) AuthToken(token string) *Client
- func (c *Client) BasePath(basePath string) *Client
- func (c *Client) Close()
- func (c *Client) ContentType(contentType string) *Client
- func (c *Client) ContentTypeFormUrlEncoded() *Client
- func (c *Client) ContentTypeHtml() *Client
- func (c *Client) ContentTypeJson() *Client
- func (c *Client) ContentTypeText() *Client
- func (c *Client) ContentTypeXml() *Client
- func (c *Client) Delete(url string, body Requester) *Req
- func (c *Client) DeleteCtx(ctx context.Context, url string, body Requester) *Req
- func (c *Client) DisableHTTP2() *Client
- func (c *Client) DisableRedirects() *Client
- func (c *Client) DisableTLSVerification() *Client
- func (c *Client) EnableCookies() *Client
- func (c *Client) FollowRedirects(maxRedirect int) *Client
- func (c *Client) Get(url string) *Req
- func (c *Client) GetCtx(ctx context.Context, url string) *Req
- func (c *Client) Head(url string) *Req
- func (c *Client) HeadCtx(ctx context.Context, url string) *Req
- func (c *Client) Header(key, val string) *Client
- func (c *Client) Patch(url string, body Requester) *Req
- func (c *Client) PatchCtx(ctx context.Context, url string, body Requester) *Req
- func (c *Client) Post(url string, body Requester) *Req
- func (c *Client) PostCtx(ctx context.Context, url string, body Requester) *Req
- func (c *Client) Put(url string, body Requester) *Req
- func (c *Client) PutCtx(ctx context.Context, url string, body Requester) *Req
- func (c *Client) QueryBool(name string, v bool) *Client
- func (c *Client) QueryBoolPtr(name string, v *bool) *Client
- func (c *Client) QueryFloat32(name string, v float32) *Client
- func (c *Client) QueryFloat32Ptr(name string, v *float32) *Client
- func (c *Client) QueryFloat64(name string, v float64) *Client
- func (c *Client) QueryFloat64Ptr(name string, v *float64) *Client
- func (c *Client) QueryInt(name string, v int) *Client
- func (c *Client) QueryInt8(name string, v int8) *Client
- func (c *Client) QueryInt8Ptr(name string, v *int8) *Client
- func (c *Client) QueryInt16(name string, v int16) *Client
- func (c *Client) QueryInt16Ptr(name string, v *int16) *Client
- func (c *Client) QueryInt32(name string, v int32) *Client
- func (c *Client) QueryInt32Ptr(name string, v *int32) *Client
- func (c *Client) QueryInt64(name string, v int64) *Client
- func (c *Client) QueryInt64Ptr(name string, v *int64) *Client
- func (c *Client) QueryIntPtr(name string, v *int) *Client
- func (c *Client) QueryString(name string, v string) *Client
- func (c *Client) QueryStringPtr(name string, v *string) *Client
- func (c *Client) QueryUint(name string, v uint) *Client
- func (c *Client) QueryUint8(name string, v uint8) *Client
- func (c *Client) QueryUint8Ptr(name string, v *uint8) *Client
- func (c *Client) QueryUint16(name string, v uint16) *Client
- func (c *Client) QueryUint16Ptr(name string, v *uint16) *Client
- func (c *Client) QueryUint32(name string, v uint32) *Client
- func (c *Client) QueryUint32Ptr(name string, v *uint32) *Client
- func (c *Client) QueryUint64(name string, v uint64) *Client
- func (c *Client) QueryUint64Ptr(name string, v *uint64) *Client
- func (c *Client) QueryUintPtr(name string, v *uint) *Client
- func (c *Client) TimeOutIn(duration time.Duration) *Client
- func (c *Client) TlsConfig(tlsConfig *tls.Config) *Client
- func (c *Client) ToStandardClient() *http.Client
- func (c *Client) Use(mws ...Middleware) *Client
- func (c *Client) UserAgent(userAgent string) *Client
- type CustomRetryChecker
- type DefaultError
- type ErrorHandler
- type LogLevel
- type Logger
- type Middleware
- func ErrorHandlerMiddleware(handler ErrorHandler) Middleware
- func LoggingMiddleware(verbose, disabled bool) Middleware
- func RequestIDMiddleware() Middleware
- func RequestModifierMiddleware(modifier RequestModifier, middlewareID string, priority int) Middleware
- func ResponseModifierMiddleware(modifier ResponseModifier, middlewareID string, priority int) Middleware
- func RetryMiddleware(maxRetries int) Middleware
- func RetryMiddlewareWithConfig(config RetryConfig) Middleware
- type Req
- func Delete(url string, body Requester) *Req
- func DeleteCtx(ctx context.Context, url string, body Requester) *Req
- func Get(url string) *Req
- func GetCtx(ctx context.Context, url string) *Req
- func Head(url string) *Req
- func HeadCtx(ctx context.Context, url string) *Req
- func Patch(url string, body Requester) *Req
- func PatchCtx(ctx context.Context, url string, body Requester) *Req
- func Post(url string, body Requester) *Req
- func PostCtx(ctx context.Context, url string, body Requester) *Req
- func Put(url string, body Requester) *Req
- func PutCtx(ctx context.Context, url string, body Requester) *Req
- func (r *Req) AcceptJson() *Req
- func (r *Req) AuthBasic(username, password string) *Req
- func (r *Req) AuthToken(token string) *Req
- func (r *Req) ContentType(contentType string) *Req
- func (r *Req) ContentTypeFormUrlEncoded() *Req
- func (r *Req) ContentTypeHtml() *Req
- func (r *Req) ContentTypeJson() *Req
- func (r *Req) ContentTypeText() *Req
- func (r *Req) ContentTypeXml() *Req
- func (r *Req) Header(key, val string) *Req
- func (r *Req) On(statusMatcher StatusMatcher, responseHandler ResponseHandler) *Req
- func (r *Req) OnAccepted(responseHandler ResponseHandler) *Req
- func (r *Req) OnAlreadyReported(responseHandler ResponseHandler) *Req
- func (r *Req) OnAny(responseHandler ResponseHandler) *Req
- func (r *Req) OnAnyExcept(statusCode int, responseHandler ResponseHandler) *Req
- func (r *Req) OnAnyExceptOneOf(responseHandler ResponseHandler, statusCodes ...int) *Req
- func (r *Req) OnBadGateway(responseHandler ResponseHandler) *Req
- func (r *Req) OnBadRequest(responseHandler ResponseHandler) *Req
- func (r *Req) OnClientError(responseHandler ResponseHandler) *Req
- func (r *Req) OnConflict(responseHandler ResponseHandler) *Req
- func (r *Req) OnContinue(responseHandler ResponseHandler) *Req
- func (r *Req) OnCreated(responseHandler ResponseHandler) *Req
- func (r *Req) OnEarlyHints(responseHandler ResponseHandler) *Req
- func (r *Req) OnExpectationFailed(responseHandler ResponseHandler) *Req
- func (r *Req) OnFailedDependency(responseHandler ResponseHandler) *Req
- func (r *Req) OnForbidden(responseHandler ResponseHandler) *Req
- func (r *Req) OnFound(responseHandler ResponseHandler) *Req
- func (r *Req) OnGatewayTimeout(responseHandler ResponseHandler) *Req
- func (r *Req) OnGone(responseHandler ResponseHandler) *Req
- func (r *Req) OnHTTPVersionNotSupported(responseHandler ResponseHandler) *Req
- func (r *Req) OnIMUsed(responseHandler ResponseHandler) *Req
- func (r *Req) OnInformational(responseHandler ResponseHandler) *Req
- func (r *Req) OnInsufficientStorage(responseHandler ResponseHandler) *Req
- func (r *Req) OnInternalServerError(responseHandler ResponseHandler) *Req
- func (r *Req) OnLengthRequired(responseHandler ResponseHandler) *Req
- func (r *Req) OnLocked(responseHandler ResponseHandler) *Req
- func (r *Req) OnLoopDetected(responseHandler ResponseHandler) *Req
- func (r *Req) OnMethodNotAllowed(responseHandler ResponseHandler) *Req
- func (r *Req) OnMisdirectedRequest(responseHandler ResponseHandler) *Req
- func (r *Req) OnMovedPermanently(responseHandler ResponseHandler) *Req
- func (r *Req) OnMultiStatus(responseHandler ResponseHandler) *Req
- func (r *Req) OnMultipleChoices(responseHandler ResponseHandler) *Req
- func (r *Req) OnNetworkAuthenticationRequired(responseHandler ResponseHandler) *Req
- func (r *Req) OnNoContent(responseHandler ResponseHandler) *Req
- func (r *Req) OnNonAuthoritativeInfo(responseHandler ResponseHandler) *Req
- func (r *Req) OnNotAcceptable(responseHandler ResponseHandler) *Req
- func (r *Req) OnNotExtended(responseHandler ResponseHandler) *Req
- func (r *Req) OnNotFound(responseHandler ResponseHandler) *Req
- func (r *Req) OnNotImplemented(responseHandler ResponseHandler) *Req
- func (r *Req) OnNotModified(responseHandler ResponseHandler) *Req
- func (r *Req) OnOk(responseHandler ResponseHandler) *Req
- func (r *Req) OnOneOf(responseHandler ResponseHandler, statusCodes ...int) *Req
- func (r *Req) OnPartialContent(responseHandler ResponseHandler) *Req
- func (r *Req) OnPaymentRequired(responseHandler ResponseHandler) *Req
- func (r *Req) OnPermanentRedirect(responseHandler ResponseHandler) *Req
- func (r *Req) OnPreconditionFailed(responseHandler ResponseHandler) *Req
- func (r *Req) OnPreconditionRequired(responseHandler ResponseHandler) *Req
- func (r *Req) OnProcessing(responseHandler ResponseHandler) *Req
- func (r *Req) OnProxyAuthRequired(responseHandler ResponseHandler) *Req
- func (r *Req) OnRedirection(responseHandler ResponseHandler) *Req
- func (r *Req) OnRequestEntityTooLarge(responseHandler ResponseHandler) *Req
- func (r *Req) OnRequestHeaderFieldsTooLarge(responseHandler ResponseHandler) *Req
- func (r *Req) OnRequestTimeout(responseHandler ResponseHandler) *Req
- func (r *Req) OnRequestURITooLong(responseHandler ResponseHandler) *Req
- func (r *Req) OnRequestedRangeNotSatisfiable(responseHandler ResponseHandler) *Req
- func (r *Req) OnResetContent(responseHandler ResponseHandler) *Req
- func (r *Req) OnSeeOther(responseHandler ResponseHandler) *Req
- func (r *Req) OnServerError(responseHandler ResponseHandler) *Req
- func (r *Req) OnServiceUnavailable(responseHandler ResponseHandler) *Req
- func (r *Req) OnSuccess(responseHandler ResponseHandler) *Req
- func (r *Req) OnSwitchingProtocols(responseHandler ResponseHandler) *Req
- func (r *Req) OnTeapot(responseHandler ResponseHandler) *Req
- func (r *Req) OnTemporaryRedirect(responseHandler ResponseHandler) *Req
- func (r *Req) OnTooEarly(responseHandler ResponseHandler) *Req
- func (r *Req) OnTooManyRequests(responseHandler ResponseHandler) *Req
- func (r *Req) OnUnauthorized(responseHandler ResponseHandler) *Req
- func (r *Req) OnUnavailableForLegalReasons(responseHandler ResponseHandler) *Req
- func (r *Req) OnUnprocessableEntity(responseHandler ResponseHandler) *Req
- func (r *Req) OnUnsupportedMediaType(responseHandler ResponseHandler) *Req
- func (r *Req) OnUpgradeRequired(responseHandler ResponseHandler) *Req
- func (r *Req) OnUseProxy(responseHandler ResponseHandler) *Req
- func (r *Req) OnVariantAlsoNegotiates(responseHandler ResponseHandler) *Req
- func (r *Req) QueryBool(name string, v bool) *Req
- func (r *Req) QueryBoolPtr(name string, v *bool) *Req
- func (r *Req) QueryFloat32(name string, v float32) *Req
- func (r *Req) QueryFloat32Ptr(name string, v *float32) *Req
- func (r *Req) QueryFloat64(name string, v float64) *Req
- func (r *Req) QueryFloat64Ptr(name string, v *float64) *Req
- func (r *Req) QueryInt(name string, v int) *Req
- func (r *Req) QueryInt8(name string, v int8) *Req
- func (r *Req) QueryInt8Ptr(name string, v *int8) *Req
- func (r *Req) QueryInt16(name string, v int16) *Req
- func (r *Req) QueryInt16Ptr(name string, v *int16) *Req
- func (r *Req) QueryInt32(name string, v int32) *Req
- func (r *Req) QueryInt32Ptr(name string, v *int32) *Req
- func (r *Req) QueryInt64(name string, v int64) *Req
- func (r *Req) QueryInt64Ptr(name string, v *int64) *Req
- func (r *Req) QueryIntPtr(name string, v *int) *Req
- func (r *Req) QueryString(name string, v string) *Req
- func (r *Req) QueryStringPtr(name string, v *string) *Req
- func (r *Req) QueryUint(name string, v uint) *Req
- func (r *Req) QueryUint8(name string, v uint8) *Req
- func (r *Req) QueryUint8Ptr(name string, v *uint8) *Req
- func (r *Req) QueryUint16(name string, v uint16) *Req
- func (r *Req) QueryUint16Ptr(name string, v *uint16) *Req
- func (r *Req) QueryUint32(name string, v uint32) *Req
- func (r *Req) QueryUint32Ptr(name string, v *uint32) *Req
- func (r *Req) QueryUint64(name string, v uint64) *Req
- func (r *Req) QueryUint64Ptr(name string, v *uint64) *Req
- func (r *Req) QueryUintPtr(name string, v *uint) *Req
- func (r *Req) Send() error
- func (r *Req) TimeOutIn(duration time.Duration) *Req
- func (r *Req) UserAgent(userAgent string) *Req
- type RequestModifier
- type Requester
- type ResponseHandler
- type ResponseModifier
- type RetryConfig
- type StatusMatcher
Constants ¶
const ( BasicAuthentication = "Basic " BearerAuthentication = "Bearer " )
const ( ContextKeyRequestID = "inpu_request_id" ContextKeyLogger = "inpu_logger" )
const ( // Content and Accept headers HeaderAccept = "Accept" HeaderAcceptCharset = "Accept-Charset" HeaderAcceptEncoding = "Accept-Encoding" HeaderAcceptLanguage = "Accept-Language" HeaderContentType = "Content-Type" HeaderContentLength = "Content-Length" HeaderContentEncoding = "Content-Encoding" // Authentication headers HeaderAuthorization = "Authorization" HeaderAPIKey = "X-Api-Key" HeaderAPISecret = "X-Api-Secret" HeaderAPIToken = "X-Api-Token" // Retry HeaderRetryAfter = "Retry-After" // Client identification HeaderUserAgent = "User-Agent" HeaderReferer = "Referer" HeaderOrigin = "Origin" // Caching and conditional requests HeaderCacheControl = "Cache-Control" HeaderIfModifiedSince = "If-Modified-Since" HeaderIfNoneMatch = "If-None-Match" HeaderIfMatch = "If-Match" HeaderIfUnmodifiedSince = "If-Unmodified-Since" HeaderIfRange = "If-Range" // Request control HeaderExpect = "Expect" HeaderRange = "Range" HeaderHost = "Host" HeaderConnection = "Connection" HeaderUpgrade = "Upgrade" HeaderTE = "TE" // Cookies and session HeaderCookie = "Cookie" // Request tracking and tracing HeaderXRequestID = "X-Request-ID" HeaderXCorrelationID = "X-Correlation-ID" HeaderXTraceID = "X-Trace-ID" HeaderXSpanID = "X-Span-ID" // Custom client headers HeaderXClientVersion = "X-Client-Version" HeaderXClientName = "X-Client-Name" HeaderXForwardedFor = "X-Forwarded-For" HeaderXRealIP = "X-Real-IP" // Security headers (client-side) HeaderXCSRFToken = "X-Csrf-Token" HeaderXRequestedWith = "X-Requested-With" // Common API headers HeaderXAPIVersion = "X-Api-Version" HeaderXClientID = "X-Client-ID" HeaderXSessionID = "X-Session-ID" HeaderXTenantID = "X-Tenant-ID" )
const ( // Text types MimeTypeText = "text/plain" MimeTypeHtml = "text/html" MimeTypeCss = "text/css" MimeTypeJavascript = "text/javascript" MimeTypeCsv = "text/csv" MimeTypeTextXml = "text/xml" MimeTypeCalendar = "text/calendar" // Application types MimeTypeJson = "application/json" MimeTypeApplicationXml = "application/xml" MimeTypeFormUrlEncoded = "application/x-www-form-urlencoded" MimeTypeMultipartFormData = "multipart/form-body" MimeTypeOctetStream = "application/octet-stream" MimeTypePdf = "application/pdf" MimeTypeZip = "application/zip" MimeTypeGzip = "application/gzip" MimeTypeTar = "application/x-tar" MimeTypeRar = "application/vnd.rar" MimeType7z = "application/x-7z-compressed" MimeTypeJsonApi = "application/vnd.api+json" MimeTypeJsonPatch = "application/json-patch+json" MimeTypeJsonMergePatch = "application/merge-patch+json" // Image types MimeTypeJpeg = "image/jpeg" MimeTypePng = "image/png" MimeTypeGif = "image/gif" MimeTypeWebp = "image/webp" MimeTypeSvg = "image/svg+xml" MimeTypeBmp = "image/bmp" MimeTypeIco = "image/x-icon" MimeTypeTiff = "image/tiff" MimeTypeAvif = "image/avif" // Audio types MimeTypeMp3 = "audio/mpeg" MimeTypeWav = "audio/wav" MimeTypeOgg = "audio/ogg" MimeTypeAac = "audio/aac" MimeTypeFlac = "audio/flac" MimeTypeM4a = "audio/mp4" // Video types MimeTypeMp4 = "video/mp4" MimeTypeAvi = "video/x-msvideo" MimeTypeMov = "video/quicktime" MimeTypeWmv = "video/x-ms-wmv" MimeTypeFlv = "video/x-flv" MimeTypeWebm = "video/webm" MimeTypeMkv = "video/x-matroska" // Font types MimeTypeWoff = "font/woff" MimeTypeWoff2 = "font/woff2" MimeTypeTtf = "font/ttf" MimeTypeOtf = "font/otf" MimeTypeEot = "application/vnd.ms-fontobject" // Microsoft Office MimeTypeDocx = "application/vnd.openxmlformats-officedocument.wordprocessingml.document" MimeTypeDoc = "application/msword" MimeTypeXlsx = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" MimeTypeXls = "application/vnd.ms-excel" MimeTypePptx = "application/vnd.openxmlformats-officedocument.presentationml.presentation" MimeTypePpt = "application/vnd.ms-powerpoint" // Other common types MimeTypeRtf = "application/rtf" MimeTypeSwf = "application/x-shockwave-flash" MimeTypeAtom = "application/atom+xml" MimeTypeRss = "application/rss+xml" MimeTypeYaml = "application/x-yaml" MimeTypeToml = "application/toml" )
const ContextKeyRetryAttempt = "inpu_retry_attempt"
const LoggerKeyRequestID = "request_id"
Variables ¶
var ( ErrRequestCreationFailed = errors.New("could not create the request") ErrInvalidBody = errors.New("could not create the body") ErrConnectionFailed = errors.New("connection failed") ErrCouldNotParseBaseUrl = errors.New("invalid base path") ErrCouldNotParsePath = errors.New("invalid path") ErrMarshalToNil = errors.New("cannot unmarshal to nil") ErrNotPointerParameter = errors.New("cannot marshal to non pointer type ") )
var DefaultLogger = NewInpuLoggerFromSlog(LogLevelInfo)
var Not = func(matcher StatusMatcher) *statusChecker { return &statusChecker{ matcher: func(statusCode int) bool { return !matcher.Match(statusCode) }, priority: matcher.Priority(), } }
var StatusAny = newStatusChecker(func(_ int) bool { return true }, 10)
StatusAny matches any status code. It can be used as fallback in case previous On matches is not called It has the least priority 10, and it is checked after StatusAnyExceptOneOf Usage: On(StatusAny,func(r *http.Response) error{})
var StatusIsAccepted = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusAccepted }, 1)
StatusIsAccepted checks if the response status is 202 Accepted. It has the priority 1, and it has the top priority. Usage: On(StatusIsAccepted, func(r *http.Response) error{}) -> only matches when the status code is 202
var StatusIsAlreadyReported = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusAlreadyReported }, 1)
StatusIsAlreadyReported checks if the response status is 208 Already Reported. It has the priority 1, and it has the top priority. Usage: On(StatusIsAlreadyReported, func(r *http.Response) error{}) -> only matches when the status code is 208
var StatusIsBadGateway = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusBadGateway }, 1)
StatusIsBadGateway checks if the response status is 502 Bad Gateway. It has the priority 1, and it has the top priority. Usage: On(StatusIsBadGateway, func(r *http.Response) error{}) -> only matches when the status code is 502
var StatusIsBadRequest = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusBadRequest }, 1)
StatusIsBadRequest checks if the response status is 400 Bad Request. It has the priority 1, and it has the top priority. Usage: On(StatusIsBadRequest, func(r *http.Response) error{}) -> only matches when the status code is 400
var StatusIsClientError = newStatusChecker(func(statusCode int) bool { return statusCode >= http.StatusBadRequest && statusCode < http.StatusInternalServerError }, 3)
StatusIsClientError checks if the response status code is between [400,500). It has the priority 3, and it is checked after StatusIsOneOf. Usage: On(StatusIsClientError,func(r *http.Response) error{})
var StatusIsConflict = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusConflict }, 1)
StatusIsConflict checks if the response status is 409 Conflict. It has the priority 1, and it has the top priority. Usage: On(StatusIsConflict, func(r *http.Response) error{}) -> only matches when the status code is 409
var StatusIsContinue = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusContinue }, 1)
StatusIsContinue checks if the response status is 100 Continue. It has the priority 1, and it has the top priority. Usage: On(StatusIsContinue, func(r *http.Response) error{}) -> only matches when the status code is 100
var StatusIsCreated = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusCreated }, 1)
StatusIsCreated checks if the response status is 201 Created. It has the priority 1, and it has the top priority. Usage: On(StatusIsCreated, func(r *http.Response) error{}) -> only matches when the status code is 201
var StatusIsEarlyHints = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusEarlyHints }, 1)
StatusIsEarlyHints checks if the response status is 103 Early Hints. It has the priority 1, and it has the top priority. Usage: On(StatusIsEarlyHints, func(r *http.Response) error{}) -> only matches when the status code is 103
var StatusIsExpectationFailed = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusExpectationFailed }, 1)
StatusIsExpectationFailed checks if the response status is 417 Expectation Failed. It has the priority 1, and it has the top priority. Usage: On(StatusIsExpectationFailed, func(r *http.Response) error{}) -> only matches when the status code is 417
var StatusIsFailedDependency = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusFailedDependency }, 1)
StatusIsFailedDependency checks if the response status is 424 Failed Dependency. It has the priority 1, and it has the top priority. Usage: On(StatusIsFailedDependency, func(r *http.Response) error{}) -> only matches when the status code is 424
var StatusIsForbidden = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusForbidden }, 1)
StatusIsForbidden checks if the response status is 403 Forbidden. It has the priority 1, and it has the top priority. Usage: On(StatusIsForbidden, func(r *http.Response) error{}) -> only matches when the status code is 403
var StatusIsFound = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusFound }, 1)
StatusIsFound checks if the response status is 302 Found. It has the priority 1, and it has the top priority. Usage: On(StatusIsFound, func(r *http.Response) error{}) -> only matches when the status code is 302
var StatusIsGatewayTimeout = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusGatewayTimeout }, 1)
StatusIsGatewayTimeout checks if the response status is 504 Gateway Timeout. It has the priority 1, and it has the top priority. Usage: On(StatusIsGatewayTimeout, func(r *http.Response) error{}) -> only matches when the status code is 504
var StatusIsGone = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusGone }, 1)
StatusIsGone checks if the response status is 410 Gone. It has the priority 1, and it has the top priority. Usage: On(StatusIsGone, func(r *http.Response) error{}) -> only matches when the status code is 410
var StatusIsHTTPVersionNotSupported = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusHTTPVersionNotSupported }, 1)
StatusIsHTTPVersionNotSupported checks if the response status is 505 HTTP Version Not Supported. It has the priority 1, and it has the top priority. Usage: On(StatusIsHTTPVersionNotSupported, func(r *http.Response) error{}) -> only matches when the status code is 505
var StatusIsIMUsed = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusIMUsed }, 1)
StatusIsIMUsed checks if the response status is 226 IM Used. It has the priority 1, and it has the top priority. Usage: On(StatusIsIMUsed, func(r *http.Response) error{}) -> only matches when the status code is 226
var StatusIsInformational = newStatusChecker(func(statusCode int) bool { return statusCode < http.StatusOK }, 3)
StatusIsInformational checks if the response status code is less than 200. It has the priority 3, and it is checked after StatusIsOneOf. Usage: On(StatusIsInformational,func(r *http.Response) error{})
var StatusIsInsufficientStorage = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusInsufficientStorage }, 1)
StatusIsInsufficientStorage checks if the response status is 507 Insufficient Storage. It has the priority 1, and it has the top priority. Usage: On(StatusIsInsufficientStorage, func(r *http.Response) error{}) -> only matches when the status code is 507
var StatusIsInternalServerError = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusInternalServerError }, 1)
StatusIsInternalServerError checks if the response status is 500 Internal Server Error. It has the priority 1, and it has the top priority. Usage: On(StatusIsInternalServerError, func(r *http.Response) error{}) -> only matches when the status code is 500
var StatusIsLengthRequired = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusLengthRequired }, 1)
StatusIsLengthRequired checks if the response status is 411 Length Required. It has the priority 1, and it has the top priority. Usage: On(StatusIsLengthRequired, func(r *http.Response) error{}) -> only matches when the status code is 411
var StatusIsLocked = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusLocked }, 1)
StatusIsLocked checks if the response status is 423 Locked. It has the priority 1, and it has the top priority. Usage: On(StatusIsLocked, func(r *http.Response) error{}) -> only matches when the status code is 423
var StatusIsLoopDetected = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusLoopDetected }, 1)
StatusIsLoopDetected checks if the response status is 508 Loop Detected. It has the priority 1, and it has the top priority. Usage: On(StatusIsLoopDetected, func(r *http.Response) error{}) -> only matches when the status code is 508
var StatusIsMethodNotAllowed = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusMethodNotAllowed }, 1)
StatusIsMethodNotAllowed checks if the response status is 405 Method Not Allowed. It has the priority 1, and it has the top priority. Usage: On(StatusIsMethodNotAllowed, func(r *http.Response) error{}) -> only matches when the status code is 405
var StatusIsMisdirectedRequest = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusMisdirectedRequest }, 1)
StatusIsMisdirectedRequest checks if the response status is 421 Misdirected Request. It has the priority 1, and it has the top priority. Usage: On(StatusIsMisdirectedRequest, func(r *http.Response) error{}) -> only matches when the status code is 421
var StatusIsMovedPermanently = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusMovedPermanently }, 1)
StatusIsMovedPermanently checks if the response status is 301 Moved Permanently. It has the priority 1, and it has the top priority. Usage: On(StatusIsMovedPermanently, func(r *http.Response) error{}) -> only matches when the status code is 301
var StatusIsMultiStatus = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusMultiStatus }, 1)
StatusIsMultiStatus checks if the response status is 207 Multi-Status. It has the priority 1, and it has the top priority. Usage: On(StatusIsMultiStatus, func(r *http.Response) error{}) -> only matches when the status code is 207
var StatusIsMultipleChoices = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusMultipleChoices }, 1)
StatusIsMultipleChoices checks if the response status is 300 Multiple Choices. It has the priority 1, and it has the top priority. Usage: On(StatusIsMultipleChoices, func(r *http.Response) error{}) -> only matches when the status code is 300
var StatusIsNetworkAuthenticationRequired = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusNetworkAuthenticationRequired }, 1)
StatusIsNetworkAuthenticationRequired checks if the response status is 511 Network Authentication Required. It has the priority 1, and it has the top priority. Usage: On(StatusIsNetworkAuthenticationRequired, func(r *http.Response) error{}) -> only matches when the status code is 511
var StatusIsNoContent = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusNoContent }, 1)
StatusIsNoContent checks if the response status is 204 No Content. It has the priority 1, and it has the top priority. Usage: On(StatusIsNoContent, func(r *http.Response) error{}) -> only matches when the status code is 204
var StatusIsNonAuthoritativeInfo = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusNonAuthoritativeInfo }, 1)
StatusIsNonAuthoritativeInfo checks if the response status is 203 Non-Authoritative Information. It has the priority 1, and it has the top priority. Usage: On(StatusIsNonAuthoritativeInfo, func(r *http.Response) error{}) -> only matches when the status code is 203
var StatusIsNotAcceptable = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusNotAcceptable }, 1)
StatusIsNotAcceptable checks if the response status is 406 Not Acceptable. It has the priority 1, and it has the top priority. Usage: On(StatusIsNotAcceptable, func(r *http.Response) error{}) -> only matches when the status code is 406
var StatusIsNotExtended = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusNotExtended }, 1)
StatusIsNotExtended checks if the response status is 510 Not Extended. It has the priority 1, and it has the top priority. Usage: On(StatusIsNotExtended, func(r *http.Response) error{}) -> only matches when the status code is 510
var StatusIsNotFound = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusNotFound }, 1)
StatusIsNotFound checks if the response status is 404 Not Found. It has the priority 1, and it has the top priority. Usage: On(StatusIsNotFound, func(r *http.Response) error{}) -> only matches when the status code is 404
var StatusIsNotImplemented = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusNotImplemented }, 1)
StatusIsNotImplemented checks if the response status is 501 Not Implemented. It has the priority 1, and it has the top priority. Usage: On(StatusIsNotImplemented, func(r *http.Response) error{}) -> only matches when the status code is 501
var StatusIsNotModified = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusNotModified }, 1)
StatusIsNotModified checks if the response status is 304 Not Modified. It has the priority 1, and it has the top priority. Usage: On(StatusIsNotModified, func(r *http.Response) error{}) -> only matches when the status code is 304
var StatusIsOk = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusOK }, 1)
StatusIsOk checks if the response status is 200 OK. It has the priority 1, and it has the top priority. Usage: On(StatusIsOk, func(r *http.Response) error{}) -> only matches when the status code is 200
var StatusIsPartialContent = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusPartialContent }, 1)
StatusIsPartialContent checks if the response status is 206 Partial Content. It has the priority 1, and it has the top priority. Usage: On(StatusIsPartialContent, func(r *http.Response) error{}) -> only matches when the status code is 206
var StatusIsPaymentRequired = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusPaymentRequired }, 1)
StatusIsPaymentRequired checks if the response status is 402 Payment Required. It has the priority 1, and it has the top priority. Usage: On(StatusIsPaymentRequired, func(r *http.Response) error{}) -> only matches when the status code is 402
var StatusIsPermanentRedirect = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusPermanentRedirect }, 1)
StatusIsPermanentRedirect checks if the response status is 308 Permanent Redirect. It has the priority 1, and it has the top priority. Usage: On(StatusIsPermanentRedirect, func(r *http.Response) error{}) -> only matches when the status code is 308
var StatusIsPreconditionFailed = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusPreconditionFailed }, 1)
StatusIsPreconditionFailed checks if the response status is 412 Precondition Failed. It has the priority 1, and it has the top priority. Usage: On(StatusIsPreconditionFailed, func(r *http.Response) error{}) -> only matches when the status code is 412
var StatusIsPreconditionRequired = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusPreconditionRequired }, 1)
StatusIsPreconditionRequired checks if the response status is 428 Precondition Required. It has the priority 1, and it has the top priority. Usage: On(StatusIsPreconditionRequired, func(r *http.Response) error{}) -> only matches when the status code is 428
var StatusIsProcessing = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusProcessing }, 1)
StatusIsProcessing checks if the response status is 102 Processing. It has the priority 1, and it has the top priority. Usage: On(StatusIsProcessing, func(r *http.Response) error{}) -> only matches when the status code is 102
var StatusIsProxyAuthRequired = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusProxyAuthRequired }, 1)
StatusIsProxyAuthRequired checks if the response status is 407 Proxy Authentication Required. It has the priority 1, and it has the top priority. Usage: On(StatusIsProxyAuthRequired, func(r *http.Response) error{}) -> only matches when the status code is 407
var StatusIsRedirection = newStatusChecker(func(statusCode int) bool { return statusCode >= http.StatusMultipleChoices && statusCode < http.StatusBadRequest }, 3)
StatusIsRedirection checks if the response status code is between [300,400). It has the priority 3, and it is checked after StatusIsOneOf. Usage: On(StatusIsRedirection,func(r *http.Response) error{})
var StatusIsRequestEntityTooLarge = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusRequestEntityTooLarge }, 1)
StatusIsRequestEntityTooLarge checks if the response status is 413 Request Entity Too Large. It has the priority 1, and it has the top priority. Usage: On(StatusIsRequestEntityTooLarge, func(r *http.Response) error{}) -> only matches when the status code is 413
var StatusIsRequestHeaderFieldsTooLarge = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusRequestHeaderFieldsTooLarge }, 1)
StatusIsRequestHeaderFieldsTooLarge checks if the response status is 431 Request Header Fields Too Large. It has the priority 1, and it has the top priority. Usage: On(StatusIsRequestHeaderFieldsTooLarge, func(r *http.Response) error{}) -> only matches when the status code is 431
var StatusIsRequestTimeout = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusRequestTimeout }, 1)
StatusIsRequestTimeout checks if the response status is 408 Request Timeout. It has the priority 1, and it has the top priority. Usage: On(StatusIsRequestTimeout, func(r *http.Response) error{}) -> only matches when the status code is 408
var StatusIsRequestURITooLong = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusRequestURITooLong }, 1)
StatusIsRequestURITooLong checks if the response status is 414 Request URI Too Long. It has the priority 1, and it has the top priority. Usage: On(StatusIsRequestURITooLong, func(r *http.Response) error{}) -> only matches when the status code is 414
var StatusIsRequestedRangeNotSatisfiable = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusRequestedRangeNotSatisfiable }, 1)
StatusIsRequestedRangeNotSatisfiable checks if the response status is 416 Requested Range Not Satisfiable. It has the priority 1, and it has the top priority. Usage: On(StatusIsRequestedRangeNotSatisfiable, func(r *http.Response) error{}) -> only matches when the status code is 416
var StatusIsResetContent = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusResetContent }, 1)
StatusIsResetContent checks if the response status is 205 Reset Content. It has the priority 1, and it has the top priority. Usage: On(StatusIsResetContent, func(r *http.Response) error{}) -> only matches when the status code is 205
var StatusIsSeeOther = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusSeeOther }, 1)
StatusIsSeeOther checks if the response status is 303 See Other. It has the priority 1, and it has the top priority. Usage: On(StatusIsSeeOther, func(r *http.Response) error{}) -> only matches when the status code is 303
var StatusIsServerError = newStatusChecker(func(statusCode int) bool {
return statusCode >= 500
}, 3)
StatusIsServerError checks if the response status is greater or equal than 500. It has the priority 3, and it is checked after StatusIsOneOf. Usage: On(StatusIsServerError,func(r *http.Response) error{})
return statusCode == http.StatusServiceUnavailable }, 1)
StatusIsServiceUnavailable checks if the response status is 503 Service Unavailable. It has the priority 1, and it has the top priority. Usage: On(StatusIsServiceUnavailable, func(r *http.Response) error{}) -> only matches when the status code is 503
var StatusIsSuccess = newStatusChecker(func(statusCode int) bool { return statusCode >= http.StatusOK && statusCode < http.StatusMultipleChoices }, 3)
StatusIsSuccess checks if the response status code is between [200,300). It has the priority 3, and it is checked after StatusIsOneOf. Usage: On(StatusIsSuccess,func(r *http.Response) error{})
var StatusIsSwitchingProtocols = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusSwitchingProtocols }, 1)
StatusIsSwitchingProtocols checks if the response status is 101 Switching Protocols. It has the priority 1, and it has the top priority. Usage: On(StatusIsSwitchingProtocols, func(r *http.Response) error{}) -> only matches when the status code is 101
var StatusIsTeapot = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusTeapot }, 1)
StatusIsTeapot checks if the response status is 418 I'm a teapot. It has the priority 1, and it has the top priority. Usage: On(StatusIsTeapot, func(r *http.Response) error{}) -> only matches when the status code is 418
var StatusIsTemporaryRedirect = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusTemporaryRedirect }, 1)
StatusIsTemporaryRedirect checks if the response status is 307 Temporary Redirect. It has the priority 1, and it has the top priority. Usage: On(StatusIsTemporaryRedirect, func(r *http.Response) error{}) -> only matches when the status code is 307
var StatusIsTooEarly = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusTooEarly }, 1)
StatusIsTooEarly checks if the response status is 425 Too Early. It has the priority 1, and it has the top priority. Usage: On(StatusIsTooEarly, func(r *http.Response) error{}) -> only matches when the status code is 425
var StatusIsTooManyRequests = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusTooManyRequests }, 1)
StatusIsTooManyRequests checks if the response status is 429 Too Many Requests. It has the priority 1, and it has the top priority. Usage: On(StatusIsTooManyRequests, func(r *http.Response) error{}) -> only matches when the status code is 429
return statusCode == http.StatusUnauthorized }, 1)
StatusIsUnauthorized checks if the response status is 401 Unauthorized. It has the priority 1, and it has the top priority. Usage: On(StatusIsUnauthorized, func(r *http.Response) error{}) -> only matches when the status code is 401
return statusCode == http.StatusUnavailableForLegalReasons }, 1)
StatusIsUnavailableForLegalReasons checks if the response status is 451 Unavailable For Legal Reasons. It has the priority 1, and it has the top priority. Usage: On(StatusIsUnavailableForLegalReasons, func(r *http.Response) error{}) -> only matches when the status code is 451
var StatusIsUnprocessableEntity = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusUnprocessableEntity }, 1)
StatusIsUnprocessableEntity checks if the response status is 422 Unprocessable Entity. It has the priority 1, and it has the top priority. Usage: On(StatusIsUnprocessableEntity, func(r *http.Response) error{}) -> only matches when the status code is 422
var StatusIsUnsupportedMediaType = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusUnsupportedMediaType }, 1)
StatusIsUnsupportedMediaType checks if the response status is 415 Unsupported Media Type. It has the priority 1, and it has the top priority. Usage: On(StatusIsUnsupportedMediaType, func(r *http.Response) error{}) -> only matches when the status code is 415
var StatusIsUpgradeRequired = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusUpgradeRequired }, 1)
StatusIsUpgradeRequired checks if the response status is 426 Upgrade Required. It has the priority 1, and it has the top priority. Usage: On(StatusIsUpgradeRequired, func(r *http.Response) error{}) -> only matches when the status code is 426
var StatusIsUseProxy = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusUseProxy }, 1)
StatusIsUseProxy checks if the response status is 305 Use Proxy. It has the priority 1, and it has the top priority. Usage: On(StatusIsUseProxy, func(r *http.Response) error{}) -> only matches when the status code is 305
var StatusIsVariantAlsoNegotiates = newStatusChecker(func(statusCode int) bool { return statusCode == http.StatusVariantAlsoNegotiates }, 1)
StatusIsVariantAlsoNegotiates checks if the response status is 506 Variant Also Negotiates. It has the priority 1, and it has the top priority. Usage: On(StatusIsVariantAlsoNegotiates, func(r *http.Response) error{}) -> only matches when the status code is 506
Functions ¶
func ContextWithLogger ¶ added in v1.2.0
func DefaultClient ¶ added in v1.2.0
DefaultClient returns a new http.Client with similar default values to http.Client, but with a non-shared Transport, idle connections disabled, and keepalives disabled.
func DefaultPooledClient ¶ added in v1.2.0
DefaultPooledClient returns a new http.Client with similar default values to http.Client, but with a shared Transport. Do not use this function for transient clients as it can leak file descriptors over time. Only use this for clients that will be re-used for the same host(s).
func DefaultPooledTransport ¶ added in v1.2.0
DefaultPooledTransport returns a new http.Transport with similar default values to http.DefaultTransport. Do not use this for transient transports as it can leak file descriptors over time. Only use this for transports that will be re-used for the same host(s).
func DefaultTransport ¶ added in v1.2.0
DefaultTransport returns a new http.Transport with similar default values to http.DefaultTransport, but with idle connections and keepalives disabled.
func DrainBodyAndClose ¶
func ExtractRequestIDFromContext ¶ added in v1.3.0
func ExtractRetryAttemptFromContext ¶ added in v1.4.0
ExtractRetryAttemptFromContext returns the current retry attempt number from the context. Returns 0 if not in a retry context (i.e., first attempt or no retry middleware).
func GetBasicAuthHeaderValue ¶ added in v1.3.0
func GetTokenHeaderValue ¶ added in v1.3.0
func ThenDoNothing ¶ added in v1.3.0
ThenDoNothing returns nil error Usage: On(StatusAny, ThenDoNothing)
func ThenReturnDefaultError ¶ added in v1.3.0
ThenReturnDefaultError returns an error that contains the request method, requests URL and the status code Usage: On(StatusAny, ThenReturnDefaultError)
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) AcceptJson ¶
func (*Client) Close ¶ added in v1.0.0
func (c *Client) Close()
Close closes all idle connections and cleans up resources. Call this when you're done using the client. After calling Close, the client should not be reused. It also cancels all the requests done via Get, Post, Put, Head, Patch, Delete, in short, methods without context.
func (*Client) ContentType ¶
func (*Client) ContentTypeFormUrlEncoded ¶
func (*Client) ContentTypeHtml ¶
func (*Client) ContentTypeJson ¶
func (*Client) ContentTypeText ¶
func (*Client) ContentTypeXml ¶
func (*Client) DisableHTTP2 ¶ added in v1.0.0
func (*Client) DisableRedirects ¶
func (*Client) DisableTLSVerification ¶ added in v1.0.0
func (*Client) EnableCookies ¶
func (*Client) FollowRedirects ¶
FollowRedirects sets how many times it should follow the redirects. Value zero disables the following.
func (*Client) ToStandardClient ¶ added in v1.0.0
func (*Client) Use ¶ added in v1.3.0
func (c *Client) Use(mws ...Middleware) *Client
type CustomRetryChecker ¶ added in v1.2.0
type DefaultError ¶ added in v1.2.0
type DefaultError struct {
// contains filtered or unexported fields
}
func (*DefaultError) Error ¶ added in v1.2.0
func (d *DefaultError) Error() string
type ErrorHandler ¶
type Logger ¶ added in v1.1.0
type Logger interface {
Error(ctx context.Context, err error, msg string, fields ...any)
Warn(ctx context.Context, msg string, fields ...any)
Info(ctx context.Context, msg string, fields ...any)
Debug(ctx context.Context, msg string, fields ...any)
}
func ExtractLoggerFromContext ¶ added in v1.3.0
func NewInpuLoggerFromSlog ¶ added in v1.3.0
type Middleware ¶
type Middleware interface {
ID() string
Priority() int
Apply(next http.RoundTripper) http.RoundTripper
}
func ErrorHandlerMiddleware ¶
func ErrorHandlerMiddleware(handler ErrorHandler) Middleware
ErrorHandlerMiddleware handles server errors
func LoggingMiddleware ¶
func LoggingMiddleware(verbose, disabled bool) Middleware
LoggingMiddleware creates a logging middleware
func RequestIDMiddleware ¶
func RequestIDMiddleware() Middleware
RequestIDMiddleware add HeaderXRequestID to every request
func RequestModifierMiddleware ¶
func RequestModifierMiddleware(modifier RequestModifier, middlewareID string, priority int) Middleware
RequestModifierMiddleware creates a middleware that allows request to be modified
func ResponseModifierMiddleware ¶
func ResponseModifierMiddleware(modifier ResponseModifier, middlewareID string, priority int) Middleware
ResponseModifierMiddleware creates a middleware that allows request to be modified
func RetryMiddleware ¶
func RetryMiddleware(maxRetries int) Middleware
RetryMiddleware creates a retry middleware with default config
func RetryMiddlewareWithConfig ¶
func RetryMiddlewareWithConfig(config RetryConfig) Middleware
RetryMiddlewareWithConfig creates a retry middleware with custom config
type Req ¶
type Req struct {
// contains filtered or unexported fields
}
func (*Req) AcceptJson ¶
func (*Req) ContentType ¶
func (*Req) ContentTypeFormUrlEncoded ¶
func (*Req) ContentTypeHtml ¶
func (*Req) ContentTypeJson ¶
func (*Req) ContentTypeText ¶
func (*Req) ContentTypeXml ¶
func (*Req) On ¶ added in v1.4.0
func (r *Req) On(statusMatcher StatusMatcher, responseHandler ResponseHandler) *Req
On adds status matcher and response handler configurations. In case a status is matched by status matcher, its response handler is executed. However, status matchers have priorities. The less priority is the higher precedence on the matching. Current status matcher priorities are: StatusIs -> 1 StatusIsOneOf -> 2 StatusIsInformational, StatusIsSuccess, StatusIsRedirection, StatusIsClientError, StatusIsServerError -> 3 StatusAnyExcept -> 8 StatusAnyExceptOneOf -> 9 StatusAny -> 10 Based on the response only one reply is executed. For example:
On(StatusIs(http.StatusOK), ThenReturnError(errors.New("something happened"))). // first one On(StatusIsSuccess, ThenReturnError(errors.New("something happened again"))). // second one On(StatusAny, ThenReturnError(errors.New("something happened again and again"))) // third one
It will execute the first response handler if the status code is 200 and return errors.New("something happened") It will execute the second response handler if the status code is 201 and return errors.New("something happened again") It will execute the third response handler if the status code is 500 or any other status code which is not success in this example and return errors.New("something happened again and again") Multiple same matcher on the same priority can be added but only first one in the addition order will be executed. For example:
On(StatusIs(http.StatusOK), ThenReturnError(errors.New("something happened"))). // first one On(StatusIs(http.StatusOK), ThenReturnError(errors.New("something happened again"))) // second one
It will return errors.New("something happened")
func (*Req) OnAccepted ¶ added in v1.4.0
func (r *Req) OnAccepted(responseHandler ResponseHandler) *Req
OnAccepted is a shorthand for On(StatusIsAccepted, responseHandler). It matches status code 202.
func (*Req) OnAlreadyReported ¶ added in v1.4.0
func (r *Req) OnAlreadyReported(responseHandler ResponseHandler) *Req
OnAlreadyReported is a shorthand for On(StatusIsAlreadyReported, responseHandler). It matches status code 208.
func (*Req) OnAny ¶ added in v1.4.0
func (r *Req) OnAny(responseHandler ResponseHandler) *Req
OnAny is a shorthand for On(StatusAny, responseHandler). It matches any status code. Useful as a fallback. Usage:
OnOk(ThenUnmarshalJsonTo(&items)). OnAny(ThenReturnDefaultError). Send()
func (*Req) OnAnyExcept ¶ added in v1.4.0
func (r *Req) OnAnyExcept(statusCode int, responseHandler ResponseHandler) *Req
OnAnyExcept is a shorthand for On(StatusAnyExcept(statusCode), responseHandler). It matches any status code except the one provided. Usage:
OnAnyExcept(http.StatusOK, ThenReturnDefaultError). Send()
func (*Req) OnAnyExceptOneOf ¶ added in v1.4.0
func (r *Req) OnAnyExceptOneOf(responseHandler ResponseHandler, statusCodes ...int) *Req
OnAnyExceptOneOf is a shorthand for On(StatusAnyExceptOneOf(statusCodes...), responseHandler). It matches any status code except those provided. Usage:
OnAnyExceptOneOf(ThenReturnDefaultError, http.StatusOK, http.StatusCreated). Send()
func (*Req) OnBadGateway ¶ added in v1.4.0
func (r *Req) OnBadGateway(responseHandler ResponseHandler) *Req
OnBadGateway is a shorthand for On(StatusIsBadGateway, responseHandler). It matches status code 502.
func (*Req) OnBadRequest ¶ added in v1.4.0
func (r *Req) OnBadRequest(responseHandler ResponseHandler) *Req
OnBadRequest is a shorthand for On(StatusIsBadRequest, responseHandler). It matches status code 400.
func (*Req) OnClientError ¶ added in v1.4.0
func (r *Req) OnClientError(responseHandler ResponseHandler) *Req
OnClientError is a shorthand for On(StatusIsClientError, responseHandler). It matches any status code in the range [400, 500).
func (*Req) OnConflict ¶ added in v1.4.0
func (r *Req) OnConflict(responseHandler ResponseHandler) *Req
OnConflict is a shorthand for On(StatusIsConflict, responseHandler). It matches status code 409.
func (*Req) OnContinue ¶ added in v1.4.0
func (r *Req) OnContinue(responseHandler ResponseHandler) *Req
OnContinue is a shorthand for On(StatusIsContinue, responseHandler). It matches status code 100.
func (*Req) OnCreated ¶ added in v1.4.0
func (r *Req) OnCreated(responseHandler ResponseHandler) *Req
OnCreated is a shorthand for On(StatusIsCreated, responseHandler). It matches status code 201.
func (*Req) OnEarlyHints ¶ added in v1.4.0
func (r *Req) OnEarlyHints(responseHandler ResponseHandler) *Req
OnEarlyHints is a shorthand for On(StatusIsEarlyHints, responseHandler). It matches status code 103.
func (*Req) OnExpectationFailed ¶ added in v1.4.0
func (r *Req) OnExpectationFailed(responseHandler ResponseHandler) *Req
OnExpectationFailed is a shorthand for On(StatusIsExpectationFailed, responseHandler). It matches status code 417.
func (*Req) OnFailedDependency ¶ added in v1.4.0
func (r *Req) OnFailedDependency(responseHandler ResponseHandler) *Req
OnFailedDependency is a shorthand for On(StatusIsFailedDependency, responseHandler). It matches status code 424.
func (*Req) OnForbidden ¶ added in v1.4.0
func (r *Req) OnForbidden(responseHandler ResponseHandler) *Req
OnForbidden is a shorthand for On(StatusIsForbidden, responseHandler). It matches status code 403.
func (*Req) OnFound ¶ added in v1.4.0
func (r *Req) OnFound(responseHandler ResponseHandler) *Req
OnFound is a shorthand for On(StatusIsFound, responseHandler). It matches status code 302.
func (*Req) OnGatewayTimeout ¶ added in v1.4.0
func (r *Req) OnGatewayTimeout(responseHandler ResponseHandler) *Req
OnGatewayTimeout is a shorthand for On(StatusIsGatewayTimeout, responseHandler). It matches status code 504.
func (*Req) OnGone ¶ added in v1.4.0
func (r *Req) OnGone(responseHandler ResponseHandler) *Req
OnGone is a shorthand for On(StatusIsGone, responseHandler). It matches status code 410.
func (*Req) OnHTTPVersionNotSupported ¶ added in v1.4.0
func (r *Req) OnHTTPVersionNotSupported(responseHandler ResponseHandler) *Req
OnHTTPVersionNotSupported is a shorthand for On(StatusIsHTTPVersionNotSupported, responseHandler). It matches status code 505.
func (*Req) OnIMUsed ¶ added in v1.4.0
func (r *Req) OnIMUsed(responseHandler ResponseHandler) *Req
OnIMUsed is a shorthand for On(StatusIsIMUsed, responseHandler). It matches status code 226.
func (*Req) OnInformational ¶ added in v1.4.0
func (r *Req) OnInformational(responseHandler ResponseHandler) *Req
OnInformational is a shorthand for On(StatusIsInformational, responseHandler). It matches any status code less than 200.
func (*Req) OnInsufficientStorage ¶ added in v1.4.0
func (r *Req) OnInsufficientStorage(responseHandler ResponseHandler) *Req
OnInsufficientStorage is a shorthand for On(StatusIsInsufficientStorage, responseHandler). It matches status code 507.
func (*Req) OnInternalServerError ¶ added in v1.4.0
func (r *Req) OnInternalServerError(responseHandler ResponseHandler) *Req
OnInternalServerError is a shorthand for On(StatusIsInternalServerError, responseHandler). It matches status code 500.
func (*Req) OnLengthRequired ¶ added in v1.4.0
func (r *Req) OnLengthRequired(responseHandler ResponseHandler) *Req
OnLengthRequired is a shorthand for On(StatusIsLengthRequired, responseHandler). It matches status code 411.
func (*Req) OnLocked ¶ added in v1.4.0
func (r *Req) OnLocked(responseHandler ResponseHandler) *Req
OnLocked is a shorthand for On(StatusIsLocked, responseHandler). It matches status code 423.
func (*Req) OnLoopDetected ¶ added in v1.4.0
func (r *Req) OnLoopDetected(responseHandler ResponseHandler) *Req
OnLoopDetected is a shorthand for On(StatusIsLoopDetected, responseHandler). It matches status code 508.
func (*Req) OnMethodNotAllowed ¶ added in v1.4.0
func (r *Req) OnMethodNotAllowed(responseHandler ResponseHandler) *Req
OnMethodNotAllowed is a shorthand for On(StatusIsMethodNotAllowed, responseHandler). It matches status code 405.
func (*Req) OnMisdirectedRequest ¶ added in v1.4.0
func (r *Req) OnMisdirectedRequest(responseHandler ResponseHandler) *Req
OnMisdirectedRequest is a shorthand for On(StatusIsMisdirectedRequest, responseHandler). It matches status code 421.
func (*Req) OnMovedPermanently ¶ added in v1.4.0
func (r *Req) OnMovedPermanently(responseHandler ResponseHandler) *Req
OnMovedPermanently is a shorthand for On(StatusIsMovedPermanently, responseHandler). It matches status code 301.
func (*Req) OnMultiStatus ¶ added in v1.4.0
func (r *Req) OnMultiStatus(responseHandler ResponseHandler) *Req
OnMultiStatus is a shorthand for On(StatusIsMultiStatus, responseHandler). It matches status code 207.
func (*Req) OnMultipleChoices ¶ added in v1.4.0
func (r *Req) OnMultipleChoices(responseHandler ResponseHandler) *Req
OnMultipleChoices is a shorthand for On(StatusIsMultipleChoices, responseHandler). It matches status code 300.
func (*Req) OnNetworkAuthenticationRequired ¶ added in v1.4.0
func (r *Req) OnNetworkAuthenticationRequired(responseHandler ResponseHandler) *Req
OnNetworkAuthenticationRequired is a shorthand for On(StatusIsNetworkAuthenticationRequired, responseHandler). It matches status code 511.
func (*Req) OnNoContent ¶ added in v1.4.0
func (r *Req) OnNoContent(responseHandler ResponseHandler) *Req
OnNoContent is a shorthand for On(StatusIsNoContent, responseHandler). It matches status code 204.
func (*Req) OnNonAuthoritativeInfo ¶ added in v1.4.0
func (r *Req) OnNonAuthoritativeInfo(responseHandler ResponseHandler) *Req
OnNonAuthoritativeInfo is a shorthand for On(StatusIsNonAuthoritativeInfo, responseHandler). It matches status code 203.
func (*Req) OnNotAcceptable ¶ added in v1.4.0
func (r *Req) OnNotAcceptable(responseHandler ResponseHandler) *Req
OnNotAcceptable is a shorthand for On(StatusIsNotAcceptable, responseHandler). It matches status code 406.
func (*Req) OnNotExtended ¶ added in v1.4.0
func (r *Req) OnNotExtended(responseHandler ResponseHandler) *Req
OnNotExtended is a shorthand for On(StatusIsNotExtended, responseHandler). It matches status code 510.
func (*Req) OnNotFound ¶ added in v1.4.0
func (r *Req) OnNotFound(responseHandler ResponseHandler) *Req
OnNotFound is a shorthand for On(StatusIsNotFound, responseHandler). It matches status code 404.
func (*Req) OnNotImplemented ¶ added in v1.4.0
func (r *Req) OnNotImplemented(responseHandler ResponseHandler) *Req
OnNotImplemented is a shorthand for On(StatusIsNotImplemented, responseHandler). It matches status code 501.
func (*Req) OnNotModified ¶ added in v1.4.0
func (r *Req) OnNotModified(responseHandler ResponseHandler) *Req
OnNotModified is a shorthand for On(StatusIsNotModified, responseHandler). It matches status code 304.
func (*Req) OnOk ¶ added in v1.4.0
func (r *Req) OnOk(responseHandler ResponseHandler) *Req
OnOk is a shorthand for On(StatusIsOk, responseHandler). It matches status code 200. Usage:
OnOk(ThenUnmarshalJsonTo(&items)). OnAny(ThenReturnDefaultError). Send()
func (*Req) OnOneOf ¶ added in v1.4.0
func (r *Req) OnOneOf(responseHandler ResponseHandler, statusCodes ...int) *Req
OnOneOf is a shorthand for On(StatusIsOneOf(statusCodes...), responseHandler). It matches any of the provided status codes. Usage:
OnOneOf(ThenUnmarshalJsonTo(&items), http.StatusOK, http.StatusCreated). Send()
func (*Req) OnPartialContent ¶ added in v1.4.0
func (r *Req) OnPartialContent(responseHandler ResponseHandler) *Req
OnPartialContent is a shorthand for On(StatusIsPartialContent, responseHandler). It matches status code 206.
func (*Req) OnPaymentRequired ¶ added in v1.4.0
func (r *Req) OnPaymentRequired(responseHandler ResponseHandler) *Req
OnPaymentRequired is a shorthand for On(StatusIsPaymentRequired, responseHandler). It matches status code 402.
func (*Req) OnPermanentRedirect ¶ added in v1.4.0
func (r *Req) OnPermanentRedirect(responseHandler ResponseHandler) *Req
OnPermanentRedirect is a shorthand for On(StatusIsPermanentRedirect, responseHandler). It matches status code 308.
func (*Req) OnPreconditionFailed ¶ added in v1.4.0
func (r *Req) OnPreconditionFailed(responseHandler ResponseHandler) *Req
OnPreconditionFailed is a shorthand for On(StatusIsPreconditionFailed, responseHandler). It matches status code 412.
func (*Req) OnPreconditionRequired ¶ added in v1.4.0
func (r *Req) OnPreconditionRequired(responseHandler ResponseHandler) *Req
OnPreconditionRequired is a shorthand for On(StatusIsPreconditionRequired, responseHandler). It matches status code 428.
func (*Req) OnProcessing ¶ added in v1.4.0
func (r *Req) OnProcessing(responseHandler ResponseHandler) *Req
OnProcessing is a shorthand for On(StatusIsProcessing, responseHandler). It matches status code 102.
func (*Req) OnProxyAuthRequired ¶ added in v1.4.0
func (r *Req) OnProxyAuthRequired(responseHandler ResponseHandler) *Req
OnProxyAuthRequired is a shorthand for On(StatusIsProxyAuthRequired, responseHandler). It matches status code 407.
func (*Req) OnRedirection ¶ added in v1.4.0
func (r *Req) OnRedirection(responseHandler ResponseHandler) *Req
OnRedirection is a shorthand for On(StatusIsRedirection, responseHandler). It matches any status code in the range [300, 400).
func (*Req) OnRequestEntityTooLarge ¶ added in v1.4.0
func (r *Req) OnRequestEntityTooLarge(responseHandler ResponseHandler) *Req
OnRequestEntityTooLarge is a shorthand for On(StatusIsRequestEntityTooLarge, responseHandler). It matches status code 413.
func (*Req) OnRequestHeaderFieldsTooLarge ¶ added in v1.4.0
func (r *Req) OnRequestHeaderFieldsTooLarge(responseHandler ResponseHandler) *Req
OnRequestHeaderFieldsTooLarge is a shorthand for On(StatusIsRequestHeaderFieldsTooLarge, responseHandler). It matches status code 431.
func (*Req) OnRequestTimeout ¶ added in v1.4.0
func (r *Req) OnRequestTimeout(responseHandler ResponseHandler) *Req
OnRequestTimeout is a shorthand for On(StatusIsRequestTimeout, responseHandler). It matches status code 408.
func (*Req) OnRequestURITooLong ¶ added in v1.4.0
func (r *Req) OnRequestURITooLong(responseHandler ResponseHandler) *Req
OnRequestURITooLong is a shorthand for On(StatusIsRequestURITooLong, responseHandler). It matches status code 414.
func (*Req) OnRequestedRangeNotSatisfiable ¶ added in v1.4.0
func (r *Req) OnRequestedRangeNotSatisfiable(responseHandler ResponseHandler) *Req
OnRequestedRangeNotSatisfiable is a shorthand for On(StatusIsRequestedRangeNotSatisfiable, responseHandler). It matches status code 416.
func (*Req) OnResetContent ¶ added in v1.4.0
func (r *Req) OnResetContent(responseHandler ResponseHandler) *Req
OnResetContent is a shorthand for On(StatusIsResetContent, responseHandler). It matches status code 205.
func (*Req) OnSeeOther ¶ added in v1.4.0
func (r *Req) OnSeeOther(responseHandler ResponseHandler) *Req
OnSeeOther is a shorthand for On(StatusIsSeeOther, responseHandler). It matches status code 303.
func (*Req) OnServerError ¶ added in v1.4.0
func (r *Req) OnServerError(responseHandler ResponseHandler) *Req
OnServerError is a shorthand for On(StatusIsServerError, responseHandler). It matches any status code greater than or equal to 500.
func (*Req) OnServiceUnavailable ¶ added in v1.4.0
func (r *Req) OnServiceUnavailable(responseHandler ResponseHandler) *Req
OnServiceUnavailable is a shorthand for On(StatusIsServiceUnavailable, responseHandler). It matches status code 503.
func (*Req) OnSuccess ¶ added in v1.4.0
func (r *Req) OnSuccess(responseHandler ResponseHandler) *Req
OnSuccess is a shorthand for On(StatusIsSuccess, responseHandler). It matches any status code in the range [200, 300). Usage:
OnSuccess(ThenUnmarshalJsonTo(&items)). Send()
func (*Req) OnSwitchingProtocols ¶ added in v1.4.0
func (r *Req) OnSwitchingProtocols(responseHandler ResponseHandler) *Req
OnSwitchingProtocols is a shorthand for On(StatusIsSwitchingProtocols, responseHandler). It matches status code 101.
func (*Req) OnTeapot ¶ added in v1.4.0
func (r *Req) OnTeapot(responseHandler ResponseHandler) *Req
OnTeapot is a shorthand for On(StatusIsTeapot, responseHandler). It matches status code 418.
func (*Req) OnTemporaryRedirect ¶ added in v1.4.0
func (r *Req) OnTemporaryRedirect(responseHandler ResponseHandler) *Req
OnTemporaryRedirect is a shorthand for On(StatusIsTemporaryRedirect, responseHandler). It matches status code 307.
func (*Req) OnTooEarly ¶ added in v1.4.0
func (r *Req) OnTooEarly(responseHandler ResponseHandler) *Req
OnTooEarly is a shorthand for On(StatusIsTooEarly, responseHandler). It matches status code 425.
func (*Req) OnTooManyRequests ¶ added in v1.4.0
func (r *Req) OnTooManyRequests(responseHandler ResponseHandler) *Req
OnTooManyRequests is a shorthand for On(StatusIsTooManyRequests, responseHandler). It matches status code 429.
func (*Req) OnUnauthorized ¶ added in v1.4.0
func (r *Req) OnUnauthorized(responseHandler ResponseHandler) *Req
OnUnauthorized is a shorthand for On(StatusIsUnauthorized, responseHandler). It matches status code 401.
func (*Req) OnUnavailableForLegalReasons ¶ added in v1.4.0
func (r *Req) OnUnavailableForLegalReasons(responseHandler ResponseHandler) *Req
OnUnavailableForLegalReasons is a shorthand for On(StatusIsUnavailableForLegalReasons, responseHandler). It matches status code 451.
func (*Req) OnUnprocessableEntity ¶ added in v1.4.0
func (r *Req) OnUnprocessableEntity(responseHandler ResponseHandler) *Req
OnUnprocessableEntity is a shorthand for On(StatusIsUnprocessableEntity, responseHandler). It matches status code 422.
func (*Req) OnUnsupportedMediaType ¶ added in v1.4.0
func (r *Req) OnUnsupportedMediaType(responseHandler ResponseHandler) *Req
OnUnsupportedMediaType is a shorthand for On(StatusIsUnsupportedMediaType, responseHandler). It matches status code 415.
func (*Req) OnUpgradeRequired ¶ added in v1.4.0
func (r *Req) OnUpgradeRequired(responseHandler ResponseHandler) *Req
OnUpgradeRequired is a shorthand for On(StatusIsUpgradeRequired, responseHandler). It matches status code 426.
func (*Req) OnUseProxy ¶ added in v1.4.0
func (r *Req) OnUseProxy(responseHandler ResponseHandler) *Req
OnUseProxy is a shorthand for On(StatusIsUseProxy, responseHandler). It matches status code 305.
func (*Req) OnVariantAlsoNegotiates ¶ added in v1.4.0
func (r *Req) OnVariantAlsoNegotiates(responseHandler ResponseHandler) *Req
OnVariantAlsoNegotiates is a shorthand for On(StatusIsVariantAlsoNegotiates, responseHandler). It matches status code 506.
type ResponseHandler ¶
ResponseHandler is the function you pass along with a status matcher in the On call. It can be
func ThenReturnError ¶ added in v1.3.0
func ThenReturnError(err error) ResponseHandler
ThenReturnError returns the provided error directly in case of status is matched Usage: On(StatusAny, ThenReturnError(errors.New("something happened")))
func ThenUnmarshalJsonAndReturnError ¶ added in v1.4.0
func ThenUnmarshalJsonAndReturnError(targetAsPointer any, err error) ResponseHandler
ThenUnmarshalJsonAndReturnError marshals the body to the pointer with ThenUnmarshalJsonTo and returns provided error. Usage: On(StatusAny, ThenUnmarshalJsonAndReturnError(&items, errors.New("request failed")))
func ThenUnmarshalJsonTo ¶ added in v1.3.0
func ThenUnmarshalJsonTo(targetAsPointer any) ResponseHandler
ThenUnmarshalJsonTo marshals the body to the pointer provided in the targetAsPointer argument. It checks if the type is pointer as well. It does not close the body because body is closed after this function is called by the caller Usage: On(StatusAny, ThenUnmarshalJsonTo(&items))
type ResponseModifier ¶
type RetryConfig ¶
type StatusMatcher ¶
func StatusAnyExcept ¶
func StatusAnyExcept(statusCode int) StatusMatcher
StatusAnyExcept matches any status code except the one provided. It has the priority 8, and it is checked after StatusIsInformational, StatusIsSuccess, StatusIsRedirection, StatusIsClientError, StatusIsServerError. Usage: On(StatusAnyExcept(http.StatusOK),func(r *http.Response) error{})
func StatusAnyExceptOneOf ¶
func StatusAnyExceptOneOf(statusCodes ...int) StatusMatcher
StatusAnyExceptOneOf matches any status code except those provided. It has the priority 9, and it is checked after StatusAnyExcept. Usage: On(StatusAnyExceptOneOf(http.StatusOK,http.StatusCreated),func(r *http.Response) error{})
func StatusIs ¶
func StatusIs(expectedStatus int) StatusMatcher
StatusIs checks if the response status is the provided status code. It has the priority 1, and it has the top priority. Usage: On(StatusIs(http.StatusOK),func(r *http.Response) error{}) -> only matches when the status code is 200
func StatusIsOneOf ¶
func StatusIsOneOf(statusCodes ...int) StatusMatcher
StatusIsOneOf checks if the response status is one of the provided codes. It has the priority 2, and it is checked after StatusIs. Usage: On(StatusIsOneOf(http.StatusOK,http.StatusCreated),func(r *http.Response) error{}) -> only matches when the status code is either 200,201