{"modulePath":"github.com/clambin/go-common/httpserver","version":"v0.13.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package httpserver\n\nPackage httpserver provides a standard way of writing an HTTP server. It supports:\n\n 1. Creating an HTTP Server listening on a static or dynamic port\n 2. Running a Prometheus metrics server\n 3. Creating an HTTP Server with one or more HTTP handlers\n 4. Recording Prometheus metrics for latency (average or quantiles) \u0026 number of requests.\n\nDeprecated: relevant parts have moved to github.com/clambin/go-common/http\n\n## Functions\n\n```go\nfunc MethodFilter(methods ...string) func(next http.Handler) http.Handler\n```\nMethodFilter only passes on the request if the http request's methos matches once of the methods. If no methods are provided, MethodFilter defaults to http.MethodGet.\n\ndeprecated: no longer needed as of Go 1.22\n\n## Types\n\n```go\ntype Handler struct {\n\t// Path of the endpoint (e.g. \"/health\"). Can be any path that's valid for gorilla/mux router's Path() method.\n\tPath string\n\t// Methods that the handler should support. If empty, defaults to http.MethodGet.\n\tMethods []string\n\t// Handler that implements the endpoint.\n\tHandler http.Handler\n}\n```\nHandler contains a path to be registered in the Server's HTTP server\n\n```go\ntype Option func(*Server)\n```\nOption specified configuration options for Server\n\n```go\nfunc WithAddr(addr string) Option\n```\nWithAddr specifies the Server's listening address.  If the port is zero, Server will listen on a random port. Use GetPort() to determine the actual listening port\n\n```go\nfunc WithHandlers(handlers []Handler) Option\n```\nWithHandlers adds the specified handlers to the server\n\n```go\nfunc WithMetrics(metrics middleware.PrometheusMetricsOptions) Option\n```\nWithMetrics will collect the specified metrics to instrument the Server's Handlers.\n\n```go\nfunc WithPrometheus(path string) Option\n```\nWithPrometheus adds a Prometheus metrics endpoint to the server at the specified Path. Default path is \"/metrics\"\n\n```go\ntype Server struct {\n\t// contains filtered or unexported fields\n}\n```\nServer implements a configurable HTTP Server. See the different WithXXX structs for available options.\n\ndeprecated: no longer in use\n\n```go\nfunc New(options ...Option) (*Server, error)\n```\nNew returns a Server with the specified options\n\ndeprecated: no longer in use\n\n```go\nfunc (s *Server) Collect(c chan\u003c- prometheus.Metric)\n```\nCollect implements the prometheus.Collector interface\n\n```go\nfunc (s *Server) Describe(descs chan\u003c- *prometheus.Desc)\n```\nDescribe implements the prometheus.Collector interface\n\n```go\nfunc (s *Server) GetPort() int\n```\nGetPort returns the HTTP Server's listening port\n\n```go\nfunc (s *Server) Serve() error\n```\nServe starts the HTTP server. When the server is shut down, it returns http.ErrServerClosed.\n\n```go\nfunc (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)\n```\nServeHTTP calls the server's handler. Mainly intended to be used in unit tests without starting the underlying HTTP server.\n\n```go\nfunc (s *Server) Shutdown(timeout time.Duration) error\n```\nShutdown performs a graceful shutdown of the HTTP server\n\n","path":"github.com/clambin/go-common/httpserver","name":"httpserver","synopsis":"Package httpserver provides a standard way of writing an HTTP server.","isRedistributable":true}
