Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GracefulServer ¶
A GracefulServer is an extension of the http.Server that enables graceful shutdown. It allows the server to smoothly stop accepting new connections while processing existing requests to completion within a specified timeout. After the timeout, ongoing connections will be forcibly closed. The default timeout is set to 5 seconds
func Bind ¶
func Bind(addr string, handler http.Handler) *GracefulServer
Bind returns a new GracefulServer configured with the provided address and handler.
func (*GracefulServer) ListenAndServeTLSWithShutdown ¶
func (s *GracefulServer) ListenAndServeTLSWithShutdown(ctx context.Context, certFile string, keyFile string, opts ...GracefulServerOption) error
ListenAndServeTLSWithShutdown starts a http.Server with the provided address, handler, certificate, and key. It behaves similarly to [ListenAndServeWithShutdown] but for HTTPS connections. For additional details, refer to the documentation of [ListenAndServeWithShutdown].
func (*GracefulServer) ListenAndServeWithShutdown ¶
func (s *GracefulServer) ListenAndServeWithShutdown(ctx context.Context, opts ...GracefulServerOption) error
ListenAndServeWithShutdown starts a http.Server with the given address and handler. It blocks until the context is canceled or an error occurs. If the context is canceled, the server will attempt a graceful shutdown. If the graceful shutdown exceeds the provided timeout, the server will be forcefully closed. The default timeout is set to 5 seconds. The context.Canceled error is intentionally ignored and thus not returned by the method. Upon timeout, the method returns only context.DeadlineExceeded error.
type GracefulServerOption ¶
type GracefulServerOption func(s *GracefulServer)
GracefulServerOption is an option used to configure a GracefulServer instance.
func WithCloudflareTLSConfig ¶
func WithCloudflareTLSConfig() GracefulServerOption
WithCloudflareTLSConfig applies TLS configuration patches to a http.Server, implementing best practice configurations inspired by Cloudflare: https://blog.cloudflare.com/exposing-go-on-the-internet/
func WithCloudflareTimeouts ¶
func WithCloudflareTimeouts() GracefulServerOption
WithCloudflareTimeouts applies timeout patches to a http.Server, implementing best practice configurations inspired by Cloudflare: https://blog.cloudflare.com/exposing-go-on-the-internet/
func WithShutdownTimeout ¶
func WithShutdownTimeout(duration time.Duration) GracefulServerOption
WithShutdownTimeout sets the timeout for a graceful shutdown, after which all active connections will be forcibly closed.
func WithTLSConfig ¶
func WithTLSConfig(config *tls.Config) GracefulServerOption
WithTLSConfig sets the provided TLS configuration for a http.Server.