httputil

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler() http.Handler

Handler returns http.Handler for the Prometheus metrics collector.

Types

type Option

type Option func(*cfg)

Option sets an optional parameter of Server.

func WithShutdownTimeout

func WithShutdownTimeout(dur time.Duration) Option

WithShutdownTimeout returns an option to set shutdown timeout of the internal HTTP server.

type Prm

type Prm struct {
	// TCP address for the server to listen on.
	//
	// Must be a valid TCP address.
	Address string

	// Must not be nil.
	Handler http.Handler
}

Prm groups the required parameters of the Server's constructor.

All values must comply with the requirements imposed on them. Passing incorrect parameter values will result in constructor failure (error or panic depending on the implementation).

type Server

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

Server represents a wrapper over http.Server that provides an interface to start and stop listening routine.

For correct operation, Server must be created using the constructor (New) based on the required parameters and optional components. After successful creation, Server is immediately ready to work through API.

func New

func New(prm Prm, opts ...Option) *Server

New creates a new instance of the Server.

Panics if at least one value of the parameters is invalid.

Panics if at least one of next optional parameters is invalid:

  • shutdown timeout is non-positive.

The created Server does not require additional initialization and is completely ready for work.

func (*Server) Serve

func (x *Server) Serve() error

Serve listens and serves the internal HTTP server.

Returns any error returned by the internal server except http.ErrServerClosed.

After Shutdown call, Serve has no effect and the returned error is always nil.

func (*Server) Shutdown

func (x *Server) Shutdown() error

Shutdown gracefully shuts down the internal HTTP server.

Shutdown is called with the context which expires after the configured timeout.

Once Shutdown has been called on a server, it may not be reused; future calls to Serve method will have no effect.

Jump to

Keyboard shortcuts

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