Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type HTTPSrvPrm ¶
type HTTPSrvPrm struct { // TCP address for the server to listen on. // // Must be a valid TCP address. Address string // Must not be nil. Handler http.Handler }
HTTPSrvPrm 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).
func NewHTTPSrvPrm ¶
func NewHTTPSrvPrm(addr string, handler http.Handler) *HTTPSrvPrm
NewHTTPSrvPrm creates a new instance of the HTTPSrvPrm.
Panics if at least one value of the parameters is invalid.
type Option ¶
type Option func(*cfg)
Option sets an optional parameter of Server.
func WithShutdownTimeout ¶
WithShutdownTimeout returns an option to set shutdown timeout of the internal HTTP server.
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 HTTPSrvPrm, 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 ¶
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.