Documentation ¶
Overview ¶
Package sentinel provides a sentinel server group.
Index ¶
- Variables
- func IgnoreError(err error) func(error) bool
- func IgnoreNetOpError(err error) bool
- func IgnoreServerClosed(err error) bool
- type Option
- type Sentinel
- func (s *Sentinel) HTTP(listener net.Listener, handler http.Handler, opts ...func(*http.Server) error) error
- func (s *Sentinel) Register(start, shutdown interface{}, ignore ...func(error) bool) error
- func (s *Sentinel) Run(ctx context.Context, timeout time.Duration, sigs ...os.Signal) error
- func (s *Sentinel) Shutdown() error
- func (s *Sentinel) ShutdownWithTimeout(ctx context.Context, timeout time.Duration) error
- type Server
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyStarted = errors.New("already started")
ErrAlreadyStarted is the already started error.
var Errorf = func(s string, v ...interface{}) { Logf("ERROR: "+s, v...) }
var Logf = log.Printf
Functions ¶
func IgnoreError ¶
IgnoreError returns a func that returns true when passed errors match.
func IgnoreNetOpError ¶
IgnoreNetOpError returns true when the passed error is a net.OpError with error "use of closed network connection".
func IgnoreServerClosed ¶
IgnoreServerClosed returns true when the passed error is the http.ErrServerClosed error.
Types ¶
type Option ¶
Option is a sentinel server group option.
func Register ¶
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
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 ¶
Sentinel is a sentinel server group that manages servers and related ignore error handlers.
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 ¶
Register registers a server to the sentinel group, a related (optional) shutdown func, and any ignore error handlers.