This module will create a kubernetes-style endpoints for Gin framework. Inspired by tavsec/gin-healthcheck.
- ⚡ Lightweight
- 🌲 Low dependency (only
gin
) - 🔥 High efficiency
- 🔨 Highly customizable
- ⎈ Kubernetes-style
go get github.com/elliotxx/healthcheck
package main
import (
"github.com/elliotxx/healthcheck"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
healthcheck.Register(&r.RouterGroup)
r.Run()
}
This will register the default healthcheck endpoint (/healthz
) to the route. The path can be customized
using healthcheck.Config
structure.
Or use NewHandler()
function directly:
package main
import (
"github.com/elliotxx/healthcheck"
"github.com/elliotxx/healthcheck/checks"
"github.com/gin-gonic/gin"
)
func main() {
r := gin.Default()
r.GET("livez", healthcheck.NewHandler(healthcheck.NewDefaultHandlerConfig()))
readyzChecks := []checks.Check{checks.NewPingCheck(), checks.NewEnvCheck("DB_HOST")}
r.GET("readyz", healthcheck.NewHandler(healthcheck.NewDefaultHandlerConfigFor(readyzChecks...)))
r.Run()
}
Output:
$ curl -k http://localhost:8080/readyz
OK
$ curl -k http://localhost:8080/readyz?verbose
[+] Ping ok
[-] Env-DB_HOST ok
health check failed
$ curl -k http://localhost:8080/readyz?verbose&excludes=Env-DB_HOST
[+] Ping ok
health check passed
Enjoy it!
More examples can be seen: ./example_test.go