https://github.com/rvflash/health
A Go package providing facilities to check liveness or readiness application dependencies.
https://github.com/rvflash/health
Last synced: 8 days ago
JSON representation
A Go package providing facilities to check liveness or readiness application dependencies.
- Host: GitHub
- URL: https://github.com/rvflash/health
- Owner: rvflash
- License: mit
- Created: 2023-04-21T21:31:31.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-21T22:30:28.000Z (about 3 years ago)
- Last Synced: 2025-10-28T23:43:22.003Z (8 months ago)
- Language: Go
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Health✓
[](https://godoc.org/github.com/rvflash/health)
[](https://github.com/rvflash/health/actions?workflow=build)
[](https://codecov.io/gh/rvflash/health)
[](https://goreportcard.com/report/github.com/rvflash/health)
`health` is a Go package providing facilities to check liveness or readiness application dependencies.
## Features
1. Exposes an HTTP handler that retrieves health status of the application with HTTP status code and JSON response.
```json
{
"date":"2023-04-21T21:54:06.238997+02:00",
"latency":"503.314958ms",
"status":"Request Timeout",
"errors":"mysql: context deadline exceeded: health: readiness probe"
}
```
2. Available strategies:
- `Liveness` to indicate if the probe failed that this instance is unhealthy and should be destroyed or restarted.
In case of error an HTTP status `ServiceUnavailable` is returned, `GatewayTimeout` in case of deadline exceeded.
- `Readiness` to notify if the probe failed that this application should no longer receive any traffic.
In case of error an HTTP status `FailedDependency` is returned, `RequestTimeout` in case of deadline exceeded.
3. Each probe has a name, a timeout, a strategy and a function to check.
4. Function interface used to check any dependency: `func(ctx context.Context) error`.
5. Provides a ready-to-use function to check file writing.
## Example
Here we create a health checker to verify MySQL database connection and NFS write access in directory named `/data`.
```go
db, err := sql.Open("mysql", "user:password@/dbname")
if err != nil {
log.Fatal(err)
}
c := health.New(
health.Probe{
Strategy: health.Readiness,
Timeout: time.Second,
Name: "mysql",
Check: db.PingContext,
},
health.Probe{
Strategy: health.Liveness,
Timeout: time.Second,
Name: "nfs",
Check: health.CreateFileCheck("/data", "check"),
},
)
http.HandleFunc("/health", health.HandlerFunc(c))
log.Fatal(http.ListenAndServe(":8080", nil))
```
> See example directory for another sample.