httpserver

package module
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2023 License: MIT Imports: 7 Imported by: 0

README

httpserver

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, port uint16, handler http.Handler, opts ...Opt) error

Run is a shortcut for New(...).Run(ctx). Port and handler parameters take precedence over the WithAddress and WithHandler options respectively if they are passed too

Types

type Opt added in v2.1.0

type Opt func(*Server)

func WithAddress

func WithAddress(host string, port uint16) Opt

func WithHandler

func WithHandler(handler http.Handler) Opt

func WithIdleTimeout

func WithIdleTimeout(d time.Duration) Opt

func WithMaxHeaderBytes

func WithMaxHeaderBytes(i int) Opt

func WithReadHeaderTimeout

func WithReadHeaderTimeout(d time.Duration) Opt

func WithReadTimeout

func WithReadTimeout(d time.Duration) Opt

func WithShutdownTimeout

func WithShutdownTimeout(d time.Duration) Opt

func WithTLSConfig

func WithTLSConfig(conf *tls.Config) Opt

func WithWriteTimeout

func WithWriteTimeout(d time.Duration) Opt

type Server

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

Server is a http server

func New

func New(opts ...Opt) *Server

New creates new Server with given options. Default options: - read timeout 30s - write timeout 30s - shutdown timeout 15s

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run runs http server and gracefully shuts it down on context cancellation. It works well in conjunction with custom os signals handling via context (signal.NotifyContext)

Directories

Path Synopsis
example
new
run

Jump to

Keyboard shortcuts

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