Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/elliotxx/healthcheck
Low-dependency, High-efficiency, Kubernetes-style healthcheck for Gin.
https://github.com/elliotxx/healthcheck
gin healthcheck healthz kubernetes
Last synced: about 2 months ago
JSON representation
Low-dependency, High-efficiency, Kubernetes-style healthcheck for Gin.
- Host: GitHub
- URL: https://github.com/elliotxx/healthcheck
- Owner: elliotxx
- License: mit
- Created: 2023-07-21T12:45:27.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-06T13:04:01.000Z (about 1 year ago)
- Last Synced: 2024-05-09T11:45:21.189Z (8 months ago)
- Topics: gin, healthcheck, healthz, kubernetes
- Language: Go
- Homepage: https://pkg.go.dev/github.com/elliotxx/healthcheck
- Size: 241 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This module will create a [**kubernetes-style** endpoints](https://kubernetes.io/docs/reference/using-api/health-checks/) for Gin framework. Inspired by [tavsec/gin-healthcheck](https://github.com/tavsec/gin-healthcheck).
## đ Language
[English](https://github.com/elliotxx/healthcheck/blob/main/README.md) | [įŽäŊä¸æ](https://github.com/elliotxx/healthcheck/blob/main/README-zh.md)
## ⨠Core Features
* ⥠Lightweight
* đ˛ Low dependency (only `gin`)
* đĨ High efficiency
* đ¨ Highly customizable
* â Kubernetes-style## âī¸ Usage
```shell
go get github.com/elliotxx/healthcheck
```## đ Examples
### Default Check
```go
package mainimport (
"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:
```go
package mainimport (
"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:
```shell
$ 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](./example_test.go)