https://github.com/superfly/fly-checks
Basic health-check framework
https://github.com/superfly/fly-checks
Last synced: about 2 months ago
JSON representation
Basic health-check framework
- Host: GitHub
- URL: https://github.com/superfly/fly-checks
- Owner: superfly
- Created: 2022-12-20T16:53:46.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-05-10T15:40:22.000Z (about 2 years ago)
- Last Synced: 2024-06-19T01:49:46.140Z (about 1 year ago)
- Language: Go
- Size: 18.6 KB
- Stars: 15
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Fly checks
Simple health-check framework.## Usage
```golang
import (
"context"
"fmt""github.com/superfly/fly-checks/check"
)func main() {
// Set an optional timeout.
timeout := 200 * time.Millisecond
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()suite := check.NewCheckSuite("my-test-function")
// Passing check
suite.AddCheck("passing_check", func() (string, error) {
return "pass", nil
})// Failing check
suite.AddCheck("failing_check", func() (string, error) {
return "failed", fmt.Errorf("random error")
})// Check that will fail due to timeout
suite.AddCheck("failing_check_due_to_timeout", func() (string, error) {
time.Sleep(time.Second)
return "failed", fmt.Errorf("random error")
})
// Optionally run something on check completion.
// suite.OnCompletion = func() {}//
go func() {
suite.Process(ctx)
cancel()
}()<-ctx.Done():
fmt.Println(suite.Result())
}
``````bash
go run main.go
[✓] passing_check: pass (83ns)
[✗] failing_check: random error (105.38µs)
[✗] failing_check_due_to_timeout: Timed out (201ms)