statping/types/failures/struct.go

43 lines
1.2 KiB
Go
Raw Normal View History

2020-03-04 10:29:00 +00:00
package failures
2018-09-18 22:02:27 +00:00
2020-03-04 10:29:00 +00:00
import "time"
2020-03-04 10:29:00 +00:00
const (
limitedFailures = 32
limitedHits = 32
)
// Failure is a failed attempt to check a service. Any a service does not meet the expected requirements,
2020-02-19 04:07:22 +00:00
// a new Failure will be inserted into Db.
type Failure struct {
2018-11-08 10:50:06 +00:00
Id int64 `gorm:"primary_key;column:id" json:"id"`
Issue string `gorm:"column:issue" json:"issue"`
Method string `gorm:"column:method" json:"method,omitempty"`
MethodId int64 `gorm:"column:method_id" json:"method_id,omitempty"`
2019-01-29 12:02:13 +00:00
ErrorCode int `gorm:"column:error_code" json:"error_code"`
2018-11-08 10:50:06 +00:00
Service int64 `gorm:"index;column:service" json:"-"`
2018-12-06 19:03:55 +00:00
Checkin int64 `gorm:"index;column:checkin" json:"-"`
2018-11-08 10:50:06 +00:00
PingTime float64 `gorm:"column:ping_time" json:"ping"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
}
// BeforeCreate for Failure will set CreatedAt to UTC
func (f *Failure) BeforeCreate() (err error) {
if f.CreatedAt.IsZero() {
f.CreatedAt = time.Now().UTC()
}
return
}
2020-02-25 07:41:28 +00:00
type FailSort []Failure
func (s FailSort) Len() int {
return len(s)
}
func (s FailSort) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s FailSort) Less(i, j int) bool {
2020-02-25 07:41:28 +00:00
return s[i].Id < s[j].Id
}