init
This commit is contained in:
42
entity.go
Normal file
42
entity.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package watchdog
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Status uint8
|
||||
|
||||
const (
|
||||
StatusUnknown Status = iota
|
||||
StatusOK
|
||||
StatusDown
|
||||
)
|
||||
|
||||
func (s Status) String() string {
|
||||
switch s {
|
||||
case StatusOK:
|
||||
return "OK"
|
||||
case StatusDown:
|
||||
return "DOWN"
|
||||
default:
|
||||
return "UNKNOWN"
|
||||
}
|
||||
}
|
||||
|
||||
// CheckFunc is a function run by Watchdog.
|
||||
// It must obey context dealine and cancellation.
|
||||
type CheckFunc func(context.Context) (Status, error)
|
||||
|
||||
// Check represents a check that must be run by Watchdog.
|
||||
type Check struct {
|
||||
Name string // indentifier of this check
|
||||
Interval time.Duration // how often the check must run (if running periodically with Start method)
|
||||
Check CheckFunc // function to run
|
||||
}
|
||||
|
||||
type CheckResult struct {
|
||||
Name string // identifier of check
|
||||
Status Status // status as retuned by CheckFunc
|
||||
Error error // error returned by CheckFunc
|
||||
}
|
Reference in New Issue
Block a user