httpclient

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package httpclient provides a centralized HTTP client factory with preset configurations.

Index

Constants

View Source
const (
	// DefaultTimeout is the standard timeout for most HTTP requests (30s).
	DefaultTimeout = 30 * time.Second

	// LongTimeout is for operations that may take longer (60s).
	LongTimeout = 60 * time.Second

	// FileUploadTimeout is for file upload operations (2 minutes).
	FileUploadTimeout = 2 * time.Minute
)

Preset timeout durations for common use cases.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) *http.Client

New creates a new HTTP client with the given options. If no timeout is specified, DefaultTimeout (30s) is used.

func NewDefault

func NewDefault() *http.Client

NewDefault creates a new HTTP client with the default timeout (30s).

func NewFileUpload

func NewFileUpload() *http.Client

NewFileUpload creates a new HTTP client for file upload operations (2 minutes).

func NewLong

func NewLong() *http.Client

NewLong creates a new HTTP client with a longer timeout (60s). Suitable for operations that may take longer, such as external API calls.

Types

type Option

type Option func(*Options)

Option is a functional option for configuring HTTP clients.

func WithTimeout

func WithTimeout(d time.Duration) Option

WithTimeout sets the client timeout.

func WithTransport

func WithTransport(t *http.Transport) Option

WithTransport sets a custom transport.

type Options

type Options struct {
	Timeout   time.Duration
	Transport *http.Transport
}

Options configures an HTTP client.

Jump to

Keyboard shortcuts

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