32 lines
576 B
Go
32 lines
576 B
Go
|
package db
|
||
|
|
||
|
import (
|
||
|
"time"
|
||
|
|
||
|
"github.com/jinzhu/gorm"
|
||
|
|
||
|
"status/check"
|
||
|
)
|
||
|
|
||
|
//PingEntry represents an entry of Ping that is persisted in the DB.
|
||
|
type PingEntry struct {
|
||
|
gorm.Model
|
||
|
ServiceName string
|
||
|
Time time.Time
|
||
|
Ping int64
|
||
|
Status check.Result
|
||
|
}
|
||
|
|
||
|
func (p PingEntry) AddToDB() {
|
||
|
if db == nil {
|
||
|
panic("DB is nil")
|
||
|
}
|
||
|
db.Create(&p)
|
||
|
}
|
||
|
|
||
|
func GetFromDB(serviceName string, from, to time.Time) []*PingEntry {
|
||
|
entries := make([]*PingEntry, 0)
|
||
|
db.Where("service_name = ? AND time BETWEEN ? AND ?", serviceName, from, to).Find(&entries)
|
||
|
return entries
|
||
|
}
|