server

package module
v0.0.0-...-9446fd8 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CertificateConfig

type CertificateConfig struct {
	CertFile string `env:"CERT_FILE" json:"certFile,omitempty" yaml:"certFile,omitempty"`
	KeyFile  string `env:"KEY_FILE" json:"keyFile,omitempty" yaml:"keyFile,omitempty"`
}

func (CertificateConfig) Certificate

func (c CertificateConfig) Certificate() (tls.Certificate, error)

func (CertificateConfig) Validate

func (c CertificateConfig) Validate() error

type Config

type Config struct {
	// Host and port to handle as https server.
	Address string `env:"ADDRESS" json:"address,omitempty" yaml:"address,omitempty"`

	// HTTP2 defines http/2 server options.
	HTTP2 *HTTP2Config `envPrefix:"HTTP2_" json:"http2,omitempty" yaml:"http2,omitempty"`

	// HTTP3 enables HTTP/3 protocol on the entryPoint. HTTP/3 requires a TCP entryPoint,
	// as HTTP/3 always starts as a TCP connection that then gets upgraded to UDP.
	// In most scenarios, this entryPoint is the same as the one used for TLS traffic.
	HTTP3 *HTTP3Config `envPrefix:"HTTP3_" json:"http3,omitempty" yaml:"http3,omitempty"`

	Transport TransportConfig `envPrefix:"TRANSPORT_" json:"transport,omitzero" yaml:"transport,omitempty"`

	TLS *TLSConfig `envPrefix:"TLS_" json:"tls,omitempty" yaml:"tls,omitempty"`
}

func (*Config) SetDefaults

func (c *Config) SetDefaults()

func (*Config) Validate

func (c *Config) Validate() error

type HTTP2Config

type HTTP2Config struct {
	// MaxConcurrentStreams specifies the number of concurrent
	// streams per connection that each client is allowed to initiate.
	// The MaxConcurrentStreams value must be greater than zero, defaults to 250.
	MaxConcurrentStreams uint32 `env:"MAX_CONCURRENT_STREAMS" json:"maxConcurrentStreams,omitempty" yaml:"maxConcurrentStreams,omitempty"`

	// MaxReadFrameSize optionally specifies the largest frame
	// this server is willing to read. A valid value is between
	// 16k and 16M, inclusive. If zero or otherwise invalid, a
	// default value is used.
	MaxReadFrameSize uint32 `env:"MAX_READ_FRAME_SIZE" json:"maxReadFrameSize,omitempty" yaml:"maxReadFrameSize,omitempty"`

	// IdleTimeout specifies how long until idle clients should be
	// closed with a GOAWAY frame. PING frames are not considered
	// activity for the purposes of IdleTimeout.
	// If zero or negative, there is no timeout.
	IdleTimeout time.Duration `env:"IDLE_TIMEOUT" json:"idleTimeout,omitempty,format:units" yaml:"idleTimeout,omitempty"`

	// ReadIdleTimeout is the timeout after which a health check using a ping
	// frame will be carried out if no frame is received on the connection.
	// If zero, no health check is performed.
	ReadIdleTimeout time.Duration `env:"READ_IDLE_TIMEOUT" json:"readIdleTimeout,omitempty,format:units" yaml:"readIdleTimeout,omitempty"`

	// PingTimeout is the timeout after which the connection will be closed
	// if a response to a ping is not received.
	// If zero, a default of 15 seconds is used.
	PingTimeout time.Duration `env:"PING_TIMEOUT" json:"pingTimeout,omitempty,format:units" yaml:"pingTimeout,omitempty"`

	// WriteByteTimeout is the timeout after which a connection will be
	// closed if no data can be written to it. The timeout begins when data is
	// available to write, and is extended whenever any bytes are written.
	// If zero or negative, there is no timeout.
	WriteByteTimeout time.Duration `env:"WRITE_BYTE_TIMEOUT" json:"writeByteTimeout,omitempty,format:units" yaml:"writeByteTimeout,omitempty"`
}

func (*HTTP2Config) SetDefaults

func (c *HTTP2Config) SetDefaults()

type HTTP3Config

type HTTP3Config struct {
	// AdvertisedPort defines which UDP port to advertise as the HTTP/3 authority.
	// It defaults to the entryPoint's address port. It can be used to override
	// the authority in the alt-svc header.
	AdvertisedPort uint `env:"ADVERTISED_PORT" json:"advertisedPort,omitempty" yaml:"advertisedPort,omitempty"`
}

type Server

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

func New

func New(cfg Config, handler http.Handler, logger *slog.Logger) *Server

func (*Server) Start

func (s *Server) Start()

func (*Server) Stop

func (s *Server) Stop(ctx context.Context) (err error)

type TLSConfig

type TLSConfig struct {
	InsecureSkipVerify bool                `env:"INSECURE_SKIP_VERIFY" json:"insecureSkipVerify,omitempty" yaml:"insecureSkipVerify,omitempty"`
	Certificates       []CertificateConfig `envPrefix:"CERTIFICATE_" json:"certificates,omitempty" yaml:"certificates,omitempty"`
}

func (TLSConfig) Validate

func (c TLSConfig) Validate() error

type TransportConfig

type TransportConfig struct {
	// ReadTimeout is the maximum duration for reading the entire
	// request, including the body. A zero or negative value means
	// there will be no timeout.
	//
	// Because ReadTimeout does not let Handlers make per-request
	// decisions on each request body's acceptable deadline or
	// upload rate, most users will prefer to use
	// ReadHeaderTimeout. It is valid to use them both.
	ReadTimeout time.Duration `env:"READ_TIMEOUT" json:"readTimeout,omitempty,format:units" yaml:"readTimeout,omitempty"`

	// ReadHeaderTimeout is the amount of time allowed to read
	// request headers. The connection's read deadline is reset
	// after reading the headers and the Handler can decide what
	// is considered too slow for the body. If zero, the value of
	// ReadTimeout is used. If negative, or if zero and ReadTimeout
	// is zero or negative, there is no timeout.
	ReadHeaderTimeout time.Duration `env:"READ_HEADER_TIMEOUT" json:"readHeaderTimeout,omitempty,format:units" yaml:"readHeaderTimeout,omitempty"`

	// WriteTimeout is the maximum duration before timing out
	// writes of the response. It is reset whenever a new
	// request's header is read. Like ReadTimeout, it does not
	// let Handlers make decisions on a per-request basis.
	// A zero or negative value means there will be no timeout.
	WriteTimeout time.Duration `env:"WRITE_TIMEOUT" json:"writeTimeout,omitempty,format:units" yaml:"writeTimeout,omitempty"`

	// IdleTimeout is the maximum amount of time to wait for the
	// next request when keep-alives are enabled. If zero, the value
	// of ReadTimeout is used. If negative, or if zero and ReadTimeout
	// is zero or negative, there is no timeout.
	IdleTimeout time.Duration `env:"IDLE_TIMEOUT" json:"idleTimeout,omitempty,format:units" yaml:"idleTimeout,omitempty"`

	// MaxHeaderBytes controls the maximum number of bytes the
	// server will read parsing the request header's keys and
	// values, including the request line. It does not limit the
	// size of the request body.
	// If zero, http.DefaultMaxHeaderBytes is used.
	MaxHeaderBytes int `env:"MAX_HEADER_BYTES" json:"maxHeaderBytes,omitempty" yaml:"maxHeaderBytes,omitempty"`
}

Jump to

Keyboard shortcuts

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