Code Walkthrough for Identified OSS Projects
graceful
options or optional configs
var (
defaultWatchInterval = time.Second
defaultStopTimeout = 20 * time.Second
defaultReloadSignals = []syscall.Signal{syscall.SIGHUP, syscall.SIGUSR1}
defaultStopSignals = []syscall.Signal{syscall.SIGKILL, syscall.SIGTERM, syscall.SIGINT}
StartedAt time.Time
)
type option struct {
reloadSignals []syscall.Signal
stopSignals []syscall.Signal
watchInterval time.Duration
stopTimeout time.Duration
}
type Option func(o *option)
// WithReloadSignals set reload signals, otherwise, default ones are used
func WithReloadSignals(sigs []syscall.Signal) Option {
return func(o *option) {
o.reloadSignals = sigs
}
}
// WithStopSignals set stop signals, otherwise, default ones are used
func WithStopSignals(sigs []syscall.Signal) Option {
return func(o *option) {
o.stopSignals = sigs
}
}
// WithStopTimeout set stop timeout for graceful shutdown
// if timeout occurs, running connections will be discard violently.
func WithStopTimeout(timeout time.Duration) Option {
return func(o *option) {
o.stopTimeout = timeout
}
}
// WithWatchInterval set watch interval for worker checking master process state
func WithWatchInterval(timeout time.Duration) Option {
return func(o *option) {
o.watchInterval = timeout
}
}
...
func NewServer(opts ...Option) *Server {
option := &option{
reloadSignals: defaultReloadSignals,
stopSignals: defaultStopSignals,
watchInterval: defaultWatchInterval,
stopTimeout: defaultStopTimeout,
}
for _, opt := range opts {
opt(option)
}
return &Server{
addrs: make([]address, 0),
handlers: make([]http.Handler, 0),
opt: option,
}
}Fork
endless
Golang-LRU
Last updated