httpserver

package
v0.0.0-...-cb66316 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, cfg Config) error

Run starts the webserver. It returns an error if the webserver is not exited gracefully

Types

type Config

type Config struct {
	// Host defaults to :8080
	Host string
	// Router is the http router
	Router http.Handler
	// ReadTimeout defaults to 1m
	ReadTimeout time.Duration
	// IdleTimeout if it's zero Go uses by default the ReadTimeout
	IdleTimeout time.Duration
	// ReadHeaderTimeout  defaults to 20s
	ReadHeaderTimeout time.Duration
	// WriteTimeout defaults to 2m
	WriteTimeout time.Duration
	// MaxHeaderBytes defaults to 1MB
	MaxHeaderBytes int
	// ExitSignals defaults to os.Interrupt
	// Here define the OS signals for which the http server should perform
	// a graceful exit
	ExitSignals []os.Signal
	// Domain by default is localhost. It is used when UseTLS = true
	// If you have a valid domain then it fetches a certificate from
	// let's encrypt. It firsts looks for a certificate in a certs folder.
	// See the getSelfSignedOrLetsEncryptCert function
	// thanks to :  https://marcofranssen.nl/build-a-go-webserver-on-http-2-using-letsencrypt
	Domain string
	// UseTLS when true it uses TLS
	UseTLS bool
}

Config contains the configuration of the web server Essentially, only the Router is mandatory in order to have a working http server with some sane defaults

Jump to

Keyboard shortcuts

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