Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GracefulShutdown ¶
type GracefulShutdown struct { Server // contains filtered or unexported fields }
GracefulShutdown is a wrapper of http.Server that can be shutdown gracefully.
func NewGracefulShutdownServer ¶
func NewGracefulShutdownServer(srv Server, opts ...Option) *GracefulShutdown
NewGracefulShutdownServer wraps the given server with graceful shutdown capability mechanism. By default, the server will listen to SIGINT and SIGTERM signals to initiate shutdown and wait for all active connections to be closed. If still active connections after wait timeout exceeded, it will force close the server. The default wait timeout is 5 seconds.
References: - https://blog.stackademic.com/graceful-shutdown-in-go-820d28e1d1c4
func (*GracefulShutdown) ListenAndServe ¶
func (gs *GracefulShutdown) ListenAndServe() error
ListenAndServe starts listening and serving the server gracefully.
type Option ¶
type Option func(*GracefulShutdown)
Option is the type for GracefulShutdown options.
func WithLogger ¶
WithLogger sets the logger for the GracefulShutdown.
func WithSignals ¶
WithSignals sets the signals to listen for initiating graceful shutdown.
func WithWaitTimeout ¶
WithWaitTimeout sets the wait timeout for graceful shutdown.
type Server ¶
type Server interface { // ListenAndServe starts listening and serving the server. // This method should block until shutdown signal received or failed to start. ListenAndServe() error // Shutdown gracefully shuts down the server, it will wait for all active connections to be closed. Shutdown(ctx context.Context) error // Close force closes the server. // Close is called when Shutdown timeout exceeded. Close() error }
Server defines a minimum methods that required for graceful shutdown procedure.