sentinel

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2020 License: MIT Imports: 10 Imported by: 0

README

About

sentinel provides a server group sentinel.

Documentation

Overview

Package sentinel provides a sentinel server group.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyStarted = errors.New("already started")

ErrAlreadyStarted is the already started error.

View Source
var Errorf = func(s string, v ...interface{}) { Logf("ERROR: "+s, v...) }
View Source
var Logf = log.Printf

Functions

func IgnoreError

func IgnoreError(err error) func(error) bool

IgnoreError returns a func that returns true when passed errors match.

func IgnoreNetOpError

func IgnoreNetOpError(err error) bool

IgnoreNetOpError returns true when the passed error is a net.OpError with error "use of closed network connection".

func IgnoreServerClosed

func IgnoreServerClosed(err error) bool

IgnoreServerClosed returns true when the passed error is the http.ErrServerClosed error.

Types

type Option

type Option = func(*Sentinel) error

Option is a sentinel server group option.

func Register

func Register(servers ...Server) Option

Register is a sentinel server group option to register a server and an associated shutdown handler.

Both server and shutdown can have a type of `func()`, `func() error`, or `func(context.Context) error`.

func RegisterIgnore added in v0.2.0

func RegisterIgnore(ignore ...func(error) bool) Option

RegisterIgnore is a sentinel server group option to add ignore error handlers.

func RegisterServer added in v0.2.0

func RegisterServer(starts ...interface{}) Option

RegisterServer is a sentinel server group option to add servers without any associated shutdown handlers.

Any server can have a type of `func()`, `func() error`, or `func(context.Context) error`.

func RegisterShutdown added in v0.2.0

func RegisterShutdown(shutdowns ...interface{}) Option

RegisterShutdown is a sentinel server group option to add a shutdown handlers without any associated servers.

Any shutdown listener can have a type of `func()`, `func() error`, or `func(context.Context) error`.

type Sentinel

type Sentinel struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Sentinel is a sentinel server group that manages servers and related ignore error handlers.

func New

func New(opts ...Option) (*Sentinel, error)

New creates a new sentinel server group.

func (*Sentinel) HTTP

func (s *Sentinel) HTTP(listener net.Listener, handler http.Handler, opts ...func(*http.Server) error) error

HTTP creates a HTTP server for the specified listener and handler, and registers the created HTTP server, its shutdown, and related ignore funcs (IgnoreServerClosed, IgnoreNetOpError) with the server sentinel group.

func (*Sentinel) Register

func (s *Sentinel) Register(start, shutdown interface{}, ignore ...func(error) bool) error

Register registers a server to the sentinel group, a related (optional) shutdown func, and any ignore error handlers.

func (*Sentinel) Run

func (s *Sentinel) Run(ctx context.Context, timeout time.Duration, sigs ...os.Signal) error

Run starts the sentinel server group.

func (*Sentinel) Shutdown

func (s *Sentinel) Shutdown() error

Shutdown calls all registered shutdown funcs.

func (*Sentinel) ShutdownWithTimeout added in v0.2.0

func (s *Sentinel) ShutdownWithTimeout(ctx context.Context, timeout time.Duration) error

ShutdownWithTimeout calls all registered shutdown funcs.

type Server

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

Server is a server.

func NewServer added in v0.2.0

func NewServer(start, shutdown interface{}) (Server, error)

NewServer creates a new server.

Jump to

Keyboard shortcuts

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