mserv

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2019 License: MIT Imports: 9 Imported by: 3

README

Mserv

Build Status

Package for grouping many servers (http, grpc, ...) and start|stop by single command. Aims to simplify startup process and controll group of servers.

Example

Start 3 http servers: pprof, prometheus, api.

// set  skipErros option for not critical component
srv1 := mserv.NewHTTPServer(&http.Server{Addr: "8080", http.DefaultServeMux}, mserv.HTTPSkipErrors(true))
srv2 := mserv.NewHTTPServer(&http.Server{Addr: "8081", promhttp.Handler()})
// set shutdown timeout
srv3 := mserv.NewHTTPServer(&http.Server{Addr: "8082", api()}, mserv.HTTPShutdownTimeout(5*time.Second))

// the servers order is keeped at startup
srvs := mserv.New(srv1, srv2, srv3)
err  := srvs.Start()
// ... do work ...
err := srvs.Stop()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GRPCServer

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

GRPCServer controll grpc server start/stop process

func (*GRPCServer) Start

func (g *GRPCServer) Start() error

Start starts grpc server

func (*GRPCServer) Stop

func (g *GRPCServer) Stop() error

Stop gracefully stops grpc server

type GRPCServerOption added in v1.0.0

type GRPCServerOption func(*GRPCServer)

GRPCServerOption allows redefine default grpc server settings

func GRPCSkipErrors added in v1.0.0

func GRPCSkipErrors(skip bool) GRPCServerOption

GRPCSkipErrors sets silent mode for Start/Stop grpc server, skip all errors

type HTTPServer

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

HTTPServer wrapper of http.Server

func (*HTTPServer) Start

func (h *HTTPServer) Start() error

Start http server

func (*HTTPServer) Stop

func (h *HTTPServer) Stop() error

Stop stops http server with timeout

type HTTPServerOption added in v1.0.0

type HTTPServerOption func(*HTTPServer)

HTTPServerOption allows configure http server optional settings

func HTTPShutdownTimeout added in v1.0.0

func HTTPShutdownTimeout(timeout time.Duration) HTTPServerOption

HTTPShutdownTimeout sets shutdown timeout

func HTTPSkipErrors added in v1.0.0

func HTTPSkipErrors(skip bool) HTTPServerOption

HTTPSkipErrors sets skip errors flag

type MultiServer

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

MultiServer is servers aggregator

func (*MultiServer) Start

func (ms *MultiServer) Start() error

Start calls Start function for each server in group, returns first error when happen

func (*MultiServer) Stop

func (ms *MultiServer) Stop() error

Stop multiple servers and returns multierrr

type RadiusOption added in v1.0.0

type RadiusOption func(*RadiusServer)

RadiusOption allows redefine default settings

func RadiusShutdownTimeout added in v1.0.0

func RadiusShutdownTimeout(timeout time.Duration) RadiusOption

RadiusShutdownTimeout sets server shutdown timout, timeout should be great then zero

func RadiusSkipErrors added in v1.0.0

func RadiusSkipErrors(skip bool) RadiusOption

RadiusSkipErrors sets skip errors flag

type RadiusServer added in v1.0.0

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

RadiusServer wraps github.com/layeh/radius packet server

func (*RadiusServer) Start added in v1.0.0

func (s *RadiusServer) Start() error

Start radius server

func (*RadiusServer) Stop added in v1.0.0

func (s *RadiusServer) Stop() error

Stop radius server

type Server

type Server interface {
	Start() error
	Stop() error
}

Server interface

func New

func New(servers ...Server) Server

New returns new multiple servers instance, skip nil servers

func NewGRPCServer

func NewGRPCServer(addr string, server *grpc.Server, opts ...GRPCServerOption) Server

NewGRPCServer returns grpc server wrapper

func NewHTTPServer

func NewHTTPServer(s *http.Server, opts ...HTTPServerOption) Server

NewHTTPServer returns new http.Server wrapper

func NewRadiusServer added in v1.0.0

func NewRadiusServer(s *radius.PacketServer, opts ...RadiusOption) (Server, error)

NewRadiusServer return server

Directories

Path Synopsis
server module

Jump to

Keyboard shortcuts

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