Documentation
¶
Overview ¶
graceful provides a wrapper around the gin.Engine to enable graceful shutdown of HTTP servers. It allows for starting, stopping, and shutting down servers with various configurations, such as listening on TCP addresses, Unix sockets, file descriptors, or custom net.Listeners.
Index ¶
- Variables
- type Graceful
- func (g *Graceful) Close()
- func (g *Graceful) Run(addr ...string) error
- func (g *Graceful) RunFd(fd uintptr) error
- func (g *Graceful) RunListener(listener net.Listener) error
- func (g *Graceful) RunTLS(addr, certFile, keyFile string) error
- func (g *Graceful) RunUnix(file string) error
- func (g *Graceful) RunWithContext(ctx context.Context) error
- func (g *Graceful) Shutdown(ctx context.Context) error
- func (g *Graceful) Start() error
- func (g *Graceful) Stop() error
- type Option
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyStarted = errors.New("already started router")
ErrAlreadyStarted is returned when trying to start a router that has already been started.
var ErrNotStarted = errors.New("router not started")
ErrNotStarted is returned when trying to stop a router that has not been started.
Functions ¶
This section is empty.
Types ¶
type Graceful ¶
Graceful wraps a gin.Engine and provides methods to start, stop, and gracefully shut down HTTP servers.
func Default ¶
Default returns a Graceful gin instance with the Logger and Recovery middleware already attached.
func (*Graceful) Close ¶
func (g *Graceful) Close()
Close gracefully shuts down the server. It first shuts down the server using the Shutdown method, then it performs any cleanup operations registered with the server. Finally, it resets the server's internal state.
func (*Graceful) Run ¶
Run attaches the router to an http.Server and starts listening and serving HTTP requests.
func (*Graceful) RunFd ¶
RunFd attaches the router to an http.Server and starts listening and serving HTTP requests through the specified file descriptor.
func (*Graceful) RunListener ¶
RunListener attaches the router to an http.Server and starts listening and serving HTTP requests through the specified net.Listener.
func (*Graceful) RunTLS ¶
RunTLS attaches the router to an http.Server and starts listening and serving HTTPS (secure) requests.
func (*Graceful) RunUnix ¶
RunUnix attaches the router to an http.Server and starts listening and serving HTTP requests through the specified Unix socket (i.e., a file).
func (*Graceful) RunWithContext ¶
RunWithContext attaches the router to the configured http.Server (fallback to configuring one on :8080 if none are configured) and starts listening and serving HTTP requests. If the passed context is canceled, the server is gracefully shut down.
func (*Graceful) Shutdown ¶
Shutdown gracefully shuts down the server without interrupting any active connections.
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option specifies instrumentation configuration options.
func WithListener ¶
WithListener configure a http.Server to listen on the given net.Listener.
func WithServer ¶
WithServer configure an existing http.Server to serve HTTP or HTTPS requests. This allows for a more complete customization of the http.Server, and srv Handler will be set to the current gin.Engine. If srv contains TLSConfig, ListenAndServeTLS will be used; otherwise, ListenAndServe will be used.