https://github.com/samgiles/health
Async healthchecks for Golang applications supporting liveness and readiness checks
https://github.com/samgiles/health
golang healthcheck k8s kubernetes microservice sre
Last synced: 2 months ago
JSON representation
Async healthchecks for Golang applications supporting liveness and readiness checks
- Host: GitHub
- URL: https://github.com/samgiles/health
- Owner: samgiles
- License: mit
- Created: 2018-10-11T17:58:25.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-11T18:13:29.000Z (over 7 years ago)
- Last Synced: 2024-11-15T01:39:37.086Z (over 1 year ago)
- Topics: golang, healthcheck, k8s, kubernetes, microservice, sre
- Language: Go
- Size: 4.88 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Async Healthcheck controller for Go
[](https://travis-ci.com/samgiles/health)
- Supports Readiness and Liveness states (k8s).
- Async healthchecks only
- Go mod support
## Example
```go
package main
import (
"fmt"
"time"
"github.com/samgiles/health"
)
type HealthCheckExample struct {
health.DefaultHealthCheck
ready bool
healthy bool
}
func (hc *HealthCheckExample) RunHealthCheck() health.HealthCheckResult {
if !hc.healthy {
return health.UnhealthyResult("Not Healthy!")
}
if !hc.ready {
return health.NotReadyResult("Not Ready!")
}
return health.HealthyResult()
}
func (hc *HealthCheckExample) HealthCheckName() string {
return "my-test-healthcheck"
}
func (hc *HealthCheckExample) HealthCheckFrequency() time.Duration {
return 5 * time.Second
}
func main() {
controller := health.NewHealthCheckController()
defer controller.Stop()
controller.AddHealthCheck(&HealthCheckExample{})
// You might use the values from Readiness and Liveness in your own router
// and response
for {
time.Sleep(5 * time.Second)
fmt.Println(controller.Readiness())
fmt.Println(controller.Liveness())
}
}
```
# License
MIT