httpserver

package module
v0.1.0 Latest Latest
Warning

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

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

README

httpserver

GitHub tag (latest by date) Codecov Test Go Report Card GitHub GoDoc

Basic instrumented HTTP server that I found myself writing over and over again.

Documentation

Authors

  • Christophe Lambin

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefBuckets = []float64{.001, .01, .1, 1, 10}
)

Functions

func InstrumentHandlerCounter

func InstrumentHandlerCounter(counter *prometheus.CounterVec, next http.Handler) http.HandlerFunc

func InstrumentHandlerDuration

func InstrumentHandlerDuration(histogram *prometheus.HistogramVec, next http.Handler) http.HandlerFunc

Types

type ApplicationServer

type ApplicationServer struct {
	Handlers []Handler
	BaseServer
}

ApplicationServer contains the configuration items for an HTTP Server

type BaseServer

type BaseServer struct {
	Port int
	// contains filtered or unexported fields
}

func (*BaseServer) GetPort

func (b *BaseServer) GetPort() int

func (*BaseServer) Run

func (b *BaseServer) Run() (err error)

Run starts the HTTP Server. This calls server's http.Server's Serve method and returns that method's return value.

func (*BaseServer) Shutdown

func (b *BaseServer) Shutdown(timeout time.Duration) (err error)

Shutdown performs a graceful shutdown of the HTTP Server.

type Handler

type Handler struct {
	// Path of the endpoint (e.g. "/health"). Must include the leading /
	Path string
	// Handler that implements the endpoint
	Handler http.Handler
	// Methods that the handler should support. If empty, http.MethodGet is the default
	Methods []string
}

Handler contains an endpoint to be registered in the Server's HTTP server, using NewWithHandlers.

type Metrics

type Metrics struct {
	RequestCounter    *prometheus.CounterVec
	DurationHistogram *prometheus.HistogramVec
}

Metrics contains the metrics that need to be captured while serving HTTP requests. If these are not provided then Server will create default metrics and register them with Prometheus' default registry.

func (*Metrics) Handle

func (m *Metrics) Handle(next http.Handler) http.Handler

type Prometheus

type Prometheus struct {
	Path string
	BaseServer
}

Prometheus contains the different Prometheus configuration options

type Server

type Server struct {
	Name string
	ApplicationServer
	Prometheus
	Metrics
}

func (*Server) Run

func (s *Server) Run() (err error)

Run starts the Server

func (*Server) Shutdown

func (s *Server) Shutdown(timeout time.Duration) (err error)

Shutdown performs a graceful shutdown of the HTTP Server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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