http

package
v0.2.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewJSONRequest

func NewJSONRequest(ctx context.Context, method, url string, payload any) (*http.Request, error)

NewJSONRequest creates an http.Request with JSON body (if payload != nil) and sets Content-Type/Accept to application/json.

func WithTimeout

WithTimeout returns a new context with timeout based on duration. If d <= 0, returns the original ctx.

Types

type Client

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

Client is a thin wrapper over net/http. It provides sane defaults and small helpers for JSON APIs.

func NewClient

func NewClient(opts *Options) *Client

func (*Client) Do

func (c *Client) Do(req *http.Request) (*http.Response, []byte, error)

func (*Client) SetClient

func (c *Client) SetClient(hc *http.Client)

SetClient overrides underlying net/http client. If provided client has Timeout set, it will be respected for request context.

type HTTPDoer

type HTTPDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

HTTPDoer is the minimal interface required from an HTTP client. Useful for tests/mocking.

type Options

type Options struct {
	Timeout         time.Duration
	KeepAlive       time.Duration
	MaxIdleConns    int
	IdleConnTimeout time.Duration
}

Options control the default net/http client. It is intentionally small (KISS) but enough for production use.

func DefaultOptions

func DefaultOptions() *Options

Jump to

Keyboard shortcuts

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