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: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultServerName               = "microcore"
	DefaultServerConcurrency        = 256 * 1024
	DefaultServerReadBufferSize     = 4096 // 4 KB
	DefaultServerWriteBufferSize    = 4096 // 4 KB
	DefaultServerReadTimeout        = 10 * time.Second
	DefaultServerWriteTimeout       = 10 * time.Second
	DefaultServerIdleTimeout        = 10 * time.Second
	DefaultServerMaxConnsPerIP      = 0               // unlimited
	DefaultServerMaxRequestsPerConn = 0               // unlimited
	DefaultServerMaxRequestBodySize = 4 * 1024 * 1024 // 4 MB
	DefaultServerDisableKeepalive   = false
	DefaultServerTCPKeepalive       = false
	DefaultServerLogAllErrors       = true
)

Variables

This section is empty.

Functions

func New

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

Types

type Option

type Option func(*fasthttp.Server)

func WithConcurrency

func WithConcurrency(concurrency int) Option

The maximum number of concurrent connections the server may serve.

func WithDisableKeepalive

func WithDisableKeepalive(disableKeepalive bool) Option

Whether to disable keep-alive connections.

The server will close all the incoming connections after sending the first response to client if this option is set to true.

func WithIdleTimeout

func WithIdleTimeout(idleTimeout time.Duration) Option

IdleTimeout is the maximum amount of time to wait for the next request when keep-alive is enabled. If IdleTimeout is zero, the value of ReadTimeout is used.

func WithLogAllErrors

func WithLogAllErrors(logAllErrors bool) Option

Logs all errors, including the most frequent 'connection reset by peer', 'broken pipe' and 'connection timeout' errors. Such errors are common in production serving real-world clients.

func WithMaxConnsPerIP

func WithMaxConnsPerIP(maxConnsPerIP int) Option

Maximum number of concurrent client connections allowed per IP.

func WithMaxRequestBodySize

func WithMaxRequestBodySize(maxRequestBodySize int) Option

Whether to disable keep-alive connections.

The server will close all the incoming connections after sending the first response to client if this option is set to true.

func WithMaxRequestsPerConn

func WithMaxRequestsPerConn(maxRequestsPerConn int) Option

Maximum number of requests served per connection.

The server closes connection after the last request. 'Connection: close' header is added to the last response.

func WithName

func WithName(name string) Option

Server name for sending in response headers.

func WithReadBufferSize

func WithReadBufferSize(readBufferSize int) Option

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

Increase this buffer if your clients send multi-KB RequestURIs and/or multi-KB headers (for example, BIG cookies).

func WithReadTimeout

func WithReadTimeout(readTimeout time.Duration) Option

ReadTimeout is the amount of time allowed to read the full request including body. The connection's read deadline is reset when the connection opens, or for keep-alive connections after the first byte has been read.

func WithTCPKeepalive

func WithTCPKeepalive(tcpKeepalive bool) Option

Whether to enable tcp keep-alive connections.

Whether the operating system should send tcp keep-alive messages on the tcp connection.

func WithWriteBufferSize

func WithWriteBufferSize(writeBufferSize int) Option

Per-connection buffer size for responses writing.

func WithWriteTimeout

func WithWriteTimeout(writeTimeout time.Duration) Option

WriteTimeout is the maximum duration before timing out writes of the response. It is reset after the request handler has returned.

Jump to

Keyboard shortcuts

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