mserv

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2020 License: MIT Imports: 8 Imported by: 3

README

Mserv

Build Status FOSSA 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 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

func HTTPWithTLSConfig added in v1.1.1

func HTTPWithTLSConfig(cfg *tls.Config) HTTPServerOption

HTTPWithTLSConfig define tls config for server

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 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 NewHTTPServer

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

NewHTTPServer returns new http.Server wrapper

Directories

Path Synopsis
server module

Jump to

Keyboard shortcuts

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