Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

Awesome Lists containing this project

README

        





Low-dependency, High-efficiency, Kubernetes-style healthcheck for Gin Framework









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 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:
```go
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:

```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)