httpclient

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasStatusCode added in v0.7.0

func HasStatusCode(err error, code int) bool

HasStatusCode checks if the error is a ResponseError with the specified HTTP status code

func IsBadRequest added in v0.7.0

func IsBadRequest(err error) bool

IsBadRequest checks if the error is a 400 Bad Request error

func IsClientError added in v0.7.0

func IsClientError(err error) bool

IsClientError checks if the error is a 4xx client error

func IsConflict added in v0.7.0

func IsConflict(err error) bool

IsConflict checks if the error is a 409 Conflict error

func IsForbidden added in v0.7.0

func IsForbidden(err error) bool

IsForbidden checks if the error is a 403 Forbidden error

func IsNotFound added in v0.7.0

func IsNotFound(err error) bool

IsNotFound checks if the error is a 404 Not Found error

func IsServerError added in v0.7.0

func IsServerError(err error) bool

IsServerError checks if the error is a 5xx server error

func IsUnauthorized added in v0.7.0

func IsUnauthorized(err error) bool

IsUnauthorized checks if the error is a 401 Unauthorized error

func IsUnprocessableEntity added in v0.7.0

func IsUnprocessableEntity(err error) bool

IsUnprocessableEntity checks if the error is a 422 Unprocessable Entity error

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(opts ...ClientOption) *Client

func (*Client) Get

func (cl *Client) Get(ctx context.Context, uri string, params url.Values, opts ...RequestOption) ([]byte, error)

func (*Client) Post added in v0.9.0

func (cl *Client) Post(ctx context.Context, uri string, body []byte, opts ...RequestOption) ([]byte, error)

func (*Client) Put added in v0.13.0

func (cl *Client) Put(ctx context.Context, uri string, body []byte, opts ...RequestOption) ([]byte, error)

type ClientOption

type ClientOption func(*Client)

func WithBaseURL

func WithBaseURL(baseURL url.URL) ClientOption

func WithDefaultExpectedStatus added in v0.11.0

func WithDefaultExpectedStatus(codes ...int) ClientOption

func WithRequestHeader added in v0.4.0

func WithRequestHeader(key, value string) ClientOption

func WithTimeout

func WithTimeout(timeout time.Duration) ClientOption

type RequestOption added in v0.11.0

type RequestOption func(*requestConfig)

func WithExpectedStatus added in v0.11.0

func WithExpectedStatus(codes ...int) RequestOption

type ResponseError added in v0.6.0

type ResponseError struct {
	Msg     string
	Code    int
	Details fmt.Stringer
}
var (
	// 4xx Client Errors
	ErrBadRequest                   ResponseError = ResponseError{Msg: "bad request", Code: http.StatusBadRequest}
	ErrUnauthorized                 ResponseError = ResponseError{Msg: "unauthorized", Code: http.StatusUnauthorized}
	ErrPaymentRequired              ResponseError = ResponseError{Msg: "payment required", Code: http.StatusPaymentRequired}
	ErrForbidden                    ResponseError = ResponseError{Msg: "forbidden", Code: http.StatusForbidden}
	ErrNotFound                     ResponseError = ResponseError{Msg: "resource not found", Code: http.StatusNotFound}
	ErrMethodNotAllowed             ResponseError = ResponseError{Msg: "method not allowed", Code: http.StatusMethodNotAllowed}
	ErrNotAcceptable                ResponseError = ResponseError{Msg: "not acceptable", Code: http.StatusNotAcceptable}
	ErrProxyAuthRequired            ResponseError = ResponseError{Msg: "proxy authentication required", Code: http.StatusProxyAuthRequired}
	ErrRequestTimeout               ResponseError = ResponseError{Msg: "request timeout", Code: http.StatusRequestTimeout}
	ErrConflict                     ResponseError = ResponseError{Msg: "conflict", Code: http.StatusConflict}
	ErrGone                         ResponseError = ResponseError{Msg: "gone", Code: http.StatusGone}
	ErrLengthRequired               ResponseError = ResponseError{Msg: "length required", Code: http.StatusLengthRequired}
	ErrPreconditionFailed           ResponseError = ResponseError{Msg: "precondition failed", Code: http.StatusPreconditionFailed}
	ErrRequestEntityTooLarge        ResponseError = ResponseError{Msg: "request entity too large", Code: http.StatusRequestEntityTooLarge}
	ErrRequestURITooLong            ResponseError = ResponseError{Msg: "request URI too long", Code: http.StatusRequestURITooLong}
	ErrUnsupportedMediaType         ResponseError = ResponseError{Msg: "unsupported media type", Code: http.StatusUnsupportedMediaType}
	ErrRequestedRangeNotSatisfiable ResponseError = ResponseError{Msg: "requested range not satisfiable", Code: http.StatusRequestedRangeNotSatisfiable}
	ErrExpectationFailed            ResponseError = ResponseError{Msg: "expectation failed", Code: http.StatusExpectationFailed}
	ErrTeapot                       ResponseError = ResponseError{Msg: "I'm a teapot", Code: http.StatusTeapot}
	ErrMisdirectedRequest           ResponseError = ResponseError{Msg: "misdirected request", Code: http.StatusMisdirectedRequest}
	ErrUnprocessableEntity          ResponseError = ResponseError{Msg: "unprocessable entity", Code: http.StatusUnprocessableEntity}
	ErrLocked                       ResponseError = ResponseError{Msg: "locked", Code: http.StatusLocked}
	ErrFailedDependency             ResponseError = ResponseError{Msg: "failed dependency", Code: http.StatusFailedDependency}
	ErrTooEarly                     ResponseError = ResponseError{Msg: "too early", Code: http.StatusTooEarly}
	ErrUpgradeRequired              ResponseError = ResponseError{Msg: "upgrade required", Code: http.StatusUpgradeRequired}
	ErrPreconditionRequired         ResponseError = ResponseError{Msg: "precondition required", Code: http.StatusPreconditionRequired}
	ErrTooManyRequests              ResponseError = ResponseError{Msg: "too many requests", Code: http.StatusTooManyRequests}
	ErrRequestHeaderFieldsTooLarge  ResponseError = ResponseError{Msg: "request header fields too large", Code: http.StatusRequestHeaderFieldsTooLarge}
	ErrUnavailableForLegalReasons   ResponseError = ResponseError{Msg: "unavailable for legal reasons", Code: http.StatusUnavailableForLegalReasons}

	// 5xx Server Errors
	ErrInternalServerError           ResponseError = ResponseError{Msg: "internal server error", Code: http.StatusInternalServerError}
	ErrNotImplemented                ResponseError = ResponseError{Msg: "not implemented", Code: http.StatusNotImplemented}
	ErrBadGateway                    ResponseError = ResponseError{Msg: "bad gateway", Code: http.StatusBadGateway}
	ErrServiceUnavailable            ResponseError = ResponseError{Msg: "service unavailable", Code: http.StatusServiceUnavailable}
	ErrGatewayTimeout                ResponseError = ResponseError{Msg: "gateway timeout", Code: http.StatusGatewayTimeout}
	ErrHTTPVersionNotSupported       ResponseError = ResponseError{Msg: "HTTP version not supported", Code: http.StatusHTTPVersionNotSupported}
	ErrVariantAlsoNegotiates         ResponseError = ResponseError{Msg: "variant also negotiates", Code: http.StatusVariantAlsoNegotiates}
	ErrInsufficientStorage           ResponseError = ResponseError{Msg: "insufficient storage", Code: http.StatusInsufficientStorage}
	ErrLoopDetected                  ResponseError = ResponseError{Msg: "loop detected", Code: http.StatusLoopDetected}
	ErrNotExtended                   ResponseError = ResponseError{Msg: "not extended", Code: http.StatusNotExtended}
	ErrNetworkAuthenticationRequired ResponseError = ResponseError{Msg: "network authentication required", Code: http.StatusNetworkAuthenticationRequired}
)

func (ResponseError) Error added in v0.6.0

func (err ResponseError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL