mserv

package module
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2019 License: MIT Imports: 7 Imported by: 0

README

Mserv

Example

func main() {
    s := mserv.New(
        // pprof
        mserv.NewHTTPServer(time.Second, &http.Server{
            Addr:    ":8081",
            Handler: http.DefaultServeMux,
        }),
        // prometheus
        mserv.NewHTTPServer(time.Second, &http.Server{
            Addr:    ":8082",
            Handler: promhttp.Handler(),
        }),
        // gin
        mserv.NewHTTPServer(5*time.Second, &http.Server{
            Addr:         ":8083",
            Handler:      ginApp(),
            ReadTimeout:  10 * time.Second,
            WriteTimeout: 10 * time.Second,
        }),
        // echo
        mserv.NewHTTPServer(5*time.Second, &http.Server{
            Addr:         ":8084",
            Handler:      echoApp(),
            TLSConfig:    &tls.Config{ /**todo**/ },
            ReadTimeout:  5 * time.Second,
            WriteTimeout: 5 * time.Second,
        }),
        // grpc
        mserv.NewGRPCServer(":8085", grpcServer()),
    )

    // start all servers
    s.Start()
    // wait stop signal
    <-grace.ShutdownContext(context.Background()).Done()
    // graceful stop each server
    s.Stop()
}

full example here

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(l Logger)

SetLogger for package usage

Types

type GRPCServer

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

func (*GRPCServer) Start

func (g *GRPCServer) Start()

func (*GRPCServer) Stop

func (g *GRPCServer) Stop()

type HTTPServer

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

HTTPServer wrapper of http.Server

func (*HTTPServer) Start

func (h *HTTPServer) Start()

Start http server in goroutine write fatal msg by log if cant start server

func (*HTTPServer) Stop

func (h *HTTPServer) Stop()

Stop http server with timeout

type Listener

type Listener interface {
	ListenAndServe() error
	Shutdown(context.Context) error
}

type Logger

type Logger interface {
	Print(v ...interface{})
	Printf(format string, v ...interface{})
}

Logger interface for package things

type MultiServer

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

MultiServer is servers aggregator

func (*MultiServer) Start

func (ms *MultiServer) Start()

Start servers

func (*MultiServer) Stop

func (ms *MultiServer) Stop()

Stop multiple servers and return concatenated error

type Serve

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

Serve wrapper for Listener interface

func (*Serve) Start

func (s *Serve) Start()

Start listener in goroutine write fatal msg by log if cant start server

func (*Serve) Stop

func (s *Serve) Stop()

Stop listener with timeout

type Server

type Server interface {
	Start()
	Stop()
}

Server interface

func New

func New(servers ...Server) Server

New yiield new multiple servers instance pointer

func NewGRPCServer

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

func NewHTTPServer

func NewHTTPServer(shutdownTimeout time.Duration, server *http.Server) Server

NewHTTPServer returns new http.Server wrapper

func NewListener

func NewListener(shutdownTimeout time.Duration, shutdownError error, server Listener) Server

NewListener returns new Listener wrapper

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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