http

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

HTTP method constants re-exported from fasthttp for use with Http.FireAndForget and similar helpers.

Variables

This section is empty.

Functions

This section is empty.

Types

type HTTPError

type HTTPError struct {
	Code int
	Body []byte
}

HTTPError is returned when the server responds with a non-2xx status code.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Http

type Http struct {
	BaseURL string
	Client  *fasthttp.Client
	// contains filtered or unexported fields
}

Http is a small JSON HTTP client built on fasthttp.

func New

func New(baseURL string, opts ...Option) *Http

New creates a new Http client.

func (*Http) Delete

func (h *Http) Delete(ctx context.Context, path string, out interface{}) (int, error)

Delete sends a DELETE request to path and JSON-decodes the response into out.

func (*Http) FireAndForget

func (h *Http) FireAndForget(ctx context.Context, method, path string, body interface{})

FireAndForget sends a request in the background, logging any error if a logger was configured via WithLogger. The caller's context values are kept but its cancellation/deadline are dropped so the request outlives the caller.

func (*Http) Get

func (h *Http) Get(ctx context.Context, path string, out interface{}) (int, error)

Get sends a GET request to path and JSON-decodes the response into out.

func (*Http) Patch

func (h *Http) Patch(ctx context.Context, path string, body, out interface{}) (int, error)

Patch sends a PATCH request with a JSON-encoded body and decodes the response into out.

func (*Http) Post

func (h *Http) Post(ctx context.Context, path string, body, out interface{}) (int, error)

Post sends a POST request with a JSON-encoded body and decodes the response into out.

func (*Http) Put

func (h *Http) Put(ctx context.Context, path string, body, out interface{}) (int, error)

Put sends a PUT request with a JSON-encoded body and decodes the response into out.

func (*Http) SetHeader

func (h *Http) SetHeader(key, value string)

SetHeader sets a default header sent with every request.

type Option

type Option func(*Http)

Option configures an Http client.

func WithClient

func WithClient(c *fasthttp.Client) Option

WithClient replaces the underlying fasthttp client.

func WithHeader

func WithHeader(key, value string) Option

WithHeader adds a default header sent with every request.

func WithLogger

func WithLogger(l *logger.Logger) Option

WithLogger attaches a logger used to report FireAndForget errors.

func WithRetry

func WithRetry(n int, backoff time.Duration) Option

WithRetry configures the number of additional retry attempts and the backoff duration between them. Only 5xx errors and transport failures are retried.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the per-request timeout used when no context deadline is present.

Jump to

Keyboard shortcuts

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