server

package
v0.0.0-...-f8e9dc7 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: BSD-3-Clause Imports: 12 Imported by: 2

README

http.server

Handles graceful shutdown for http servers, as well as sane defaults for payloads (max body size).

Documentation

Index

Constants

View Source
const (
	MB = 1 << 20 // 1 MB

)

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(port string, handler http.Handler, opts ...Option)

ListenAndServe starts the HTTP server with some sane defaults.

func ListenAndServeForever

func ListenAndServeForever(port string, handler http.Handler, opts ...Option)

ListenAndServeForever allows zero-downtime upgrade. This is done by sending the signal SIGUSR2 to the binary. The binary will fork a child process and the parent process will exit. The child process will inherit the listener and continue serving requests. The parent process will gracefully shutdown after serving all the requests. E.g.

$ go build -o main $ kill -SIGUSR2 `lsof -ti:8080` $ curl localhost:8080

Types

type MaxBytes

type MaxBytes int64

func (MaxBytes) Apply

func (r MaxBytes) Apply(s *http.Server)

type Option

type Option interface {
	Apply(s *http.Server)
}

type ReadHeaderTimeout

type ReadHeaderTimeout time.Duration

func (ReadHeaderTimeout) Apply

func (r ReadHeaderTimeout) Apply(s *http.Server)

type ReadTimeout

type ReadTimeout time.Duration

func (ReadTimeout) Apply

func (r ReadTimeout) Apply(s *http.Server)

type Timeout

type Timeout struct {
	Duration time.Duration
	Message  string
}

func (Timeout) Apply

func (r Timeout) Apply(s *http.Server)

type WriteTimeout

type WriteTimeout time.Duration

func (WriteTimeout) Apply

func (r WriteTimeout) Apply(s *http.Server)

Jump to

Keyboard shortcuts

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