grace

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 7 Imported by: 0

README

Grace - Graceful HTTP Server Shutdown

Installation

go get github.com/davidsugianto/go-pkgs/grace

Usage

Replace your existing server start call:

// BEFORE
http.ListenAndServe(":8080", handler)

// AFTER
grace.ServeHTTP(":8080", handler)

That's it! Works with any framework.

Examples

Standard Library

import "github.com/davidsugianto/go-pkgs/grace"

http.HandleFunc("/", handler)
grace.ServeHTTP(":8080", nil)

Gin

r := gin.Default()
grace.ServeHTTP(":8080", r)

Echo

e := echo.New()
grace.ServeHTTP(":8080", e)

Any Framework

grace.ServeHTTP(":8080", yourHandler)
HTTPS
grace.ServeHTTPS(":8443", "cert.pem", "key.pem", handler)
Custom Server
server := &http.Server{...}
grace.ServeServer(server)

What It Does

  • Starts your HTTP server normally
  • Listens for SIGINT/SIGTERM signals
  • Stops accepting new connections
  • Waits up to 30 seconds for active requests to complete
  • Gracefully shuts down

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ServeHTTP

func ServeHTTP(addr string, handler http.Handler) error

func ServeHTTPS

func ServeHTTPS(addr, certFile, keyFile string, handler http.Handler) error

func ServeServer

func ServeServer(server *http.Server) error

func ServeServerTLS

func ServeServerTLS(server *http.Server, certFile, keyFile string) error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL