http

package
v4.13.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(ctx context.Context, addr string, srv *http.Server) error

ListenAndServe serves an http server over TCP

func ListenAndServeMonitoring

func ListenAndServeMonitoring(ctx context.Context, addr string, healthHandler http.Handler) error

ListenAndServeMonitoring starts up an HTTP server serving /metrics and /health.

When the context is canceled, the server will be gracefully shutdown.

func ListenAndServePprof

func ListenAndServePprof(ctx context.Context, addr string) error

ListenAndServePprof starts a pprof server

func New

func New(cfg *Config) (*http.Server, error)

New creates a new http server

Example:

srv, _ := server.New(&server.Config{
 Addr: ":8080",
 Handler: http.DefaultServeMux,
 Options: []server.Option{
   server.WithLogging("my-server"),
   server.WithMetrics("my-server"),
   server.WithRecovery(),
   server.WithTracing("opentracing-server:6831", "my-server"),
 }
})

srv.ListenAndServe(context.Background())

Types

type Config

type Config struct {
	Addr    string
	Handler http.Handler
	Options []Option
}

Config contains the http servers config options

type Option

type Option interface {
	WrapHandler(handler http.Handler) http.Handler
}

Option is the interface for all server options defined in this package

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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