core

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// Client name. Used in User-Agent request header.
	DefaultClientName = "microcore"

	// Maximum number of connections per each host which may be established.
	DefaultClientMaxConnsPerHost = 512

	// Idle keep-alive connections are closed after this duration.
	DefaultClientMaxIdleConnDuration = 10 * time.Second

	// Keep-alive connections are closed after this duration.
	DefaultClientMaxConnDuration = time.Duration(0)

	// Maximum number of attempts for idempotent calls.
	DefaultClientMaxIdemponentCallAttempts = 5

	// Per-connection buffer size for responses' reading.
	// This also limits the maximum header size.
	DefaultClientReadBufferSize = 4096

	// Per-connection buffer size for requests' writing.
	DefaultClientWriteBufferSize = 4096

	// Maximum duration for full response reading (including body).
	DefaultClientReadTimeout = 10 * time.Second

	// Maximum duration for full request writing (including body).
	DefaultClientWriteTimeout = 10 * time.Second

	// Header names are passed as-is without normalization
	// if this option is set.
	DefaultClientDisableHeaderNamesNormalizing = false

	// Path values are sent as-is without normalization.
	DefaultClientDisablePathNormalizing = false
)

Variables

This section is empty.

Functions

func New

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

Types

type Option

type Option func(*fasthttp.Client)

func WithConfigureClient

func WithConfigureClient(configureClient func(hc *fasthttp.HostClient) error) Option

ConfigureClient configures the fasthttp.HostClient.

func WithConnPoolStrategy

func WithConnPoolStrategy(connPoolStrategy fasthttp.ConnPoolStrategyType) Option

Connection pool strategy. Can be either LIFO or FIFO (default).

func WithDial

func WithDial(dial fasthttp.DialFunc) Option

Callback for establishing new connections to hosts.

Note that if Dial is set instead of DialTimeout, Dial will ignore Request timeout. If you want the tcp dial process to account for request timeouts, use DialTimeout instead.

If not set, DialTimeout is used.

func WithDialDualStack

func WithDialDualStack(dialDualStack bool) Option

Attempt to connect to both ipv4 and ipv6 addresses if set to true.

This option is used only if default TCP dialer is used, i.e. if Dial is blank.

By default client connects only to ipv4 addresses, since unfortunately ipv6 remains broken in many networks worldwide :)

func WithDialTimeout

func WithDialTimeout(dialTimeout fasthttp.DialFuncWithTimeout) Option

Callback for establishing new connections to hosts.

Default DialTimeout is used if not set.

func WithDisableHeaderNamesNormalizing

func WithDisableHeaderNamesNormalizing(disableHeaderNamesNormalizing bool) Option

Header names are passed as-is without normalization if this option is set.

Disabled header names' normalization may be useful only for proxying responses to other clients expecting case-sensitive header names. See https://github.com/valyala/fasthttp/issues/57 for details.

By default request and response header names are normalized, i.e. The first letter and the first letters following dashes are uppercased, while all the other letters are lowercased. Examples:

  • HOST -> Host
  • content-type -> Content-Type
  • cONTENT-lenGTH -> Content-Length

func WithDisablePathNormalizing

func WithDisablePathNormalizing(disablePathNormalizing bool) Option

Path values are sent as-is without normalization.

Disabled path normalization may be useful for proxying incoming requests to servers that are expecting paths to be forwarded as-is.

By default path values are normalized, i.e. extra slashes are removed, special characters are encoded.

func WithMaxConnDuration

func WithMaxConnDuration(maxConnDuration time.Duration) Option

Keep-alive connections are closed after this duration.

By default connection duration is unlimited.

func WithMaxConnWaitTimeout

func WithMaxConnWaitTimeout(maxConnWaitTimeout time.Duration) Option

Maximum duration for waiting for a free connection.

By default will not waiting, return ErrNoFreeConns immediately.

func WithMaxConnsPerHost

func WithMaxConnsPerHost(maxConnsPerHost int) Option

Maximum number of connections per each host which may be established.

DefaultMaxConnsPerHost is used if not set.

func WithMaxIdemponentCallAttempts

func WithMaxIdemponentCallAttempts(maxIdemponentCallAttempts int) Option

Maximum number of attempts for idempotent calls.

DefaultMaxIdemponentCallAttempts is used if not set.

func WithMaxIdleConnDuration

func WithMaxIdleConnDuration(maxIdleConnDuration time.Duration) Option

Idle keep-alive connections are closed after this duration.

By default idle connections are closed after DefaultMaxIdleConnDuration.

func WithMaxResponseBodySize

func WithMaxResponseBodySize(maxResponseBodySize int) Option

Maximum response body size.

The client returns ErrBodyTooLarge if this limit is greater than 0 and response body is greater than the limit.

By default response body size is unlimited.

func WithName

func WithName(name string) Option

Client name. Used in User-Agent request header.

Default client name is used if not set.

func WithNoDefaultUserAgentHeader

func WithNoDefaultUserAgentHeader(noDefaultUserAgentHeader bool) Option

NoDefaultUserAgentHeader when set to true, causes the default User-Agent header to be excluded from the Request.

func WithReadBufferSize

func WithReadBufferSize(readBufferSize int) Option

Per-connection buffer size for responses' reading. This also limits the maximum header size.

Default buffer size is used if 0.

func WithReadTimeout

func WithReadTimeout(readTimeout time.Duration) Option

Maximum duration for full response reading (including body).

By default response read timeout is unlimited.

func WithRetryIfErr

func WithRetryIfErr(retryIfErr fasthttp.RetryIfErrFunc) Option

When the client encounters an error during a request, the behavior—whether to retry and whether to reset the request timeout—should be determined based on the return value of this field. This field is only effective within the range of MaxIdemponentCallAttempts.

func WithStreamResponseBody

func WithStreamResponseBody(streamResponseBody bool) Option

StreamResponseBody enables response body streaming.

func WithTLSConfig

func WithTLSConfig(tlsConfig *tls.Config) Option

TLS config for https connections.

Default TLS config is used if not set.

func WithTransport

func WithTransport(transport fasthttp.RoundTripper) Option

Transport defines a transport-like mechanism that wraps every request/response.

func WithWriteBufferSize

func WithWriteBufferSize(writeBufferSize int) Option

Per-connection buffer size for requests' writing.

Default buffer size is used if 0.

func WithWriteTimeout

func WithWriteTimeout(writeTimeout time.Duration) Option

Maximum duration for full request writing (including body).

By default request write timeout is unlimited.

Jump to

Keyboard shortcuts

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