httputil

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 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 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 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 optinal 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 internal HTTP server.

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

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

func (*Server) Shutdown

func (x *Server) Shutdown() error

Shutdown gracefully shuts down internal HTTP server.

Shutdown is called with context which expires after 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