-
Notifications
You must be signed in to change notification settings - Fork 0
/
persisted_measurement.go
49 lines (43 loc) · 994 Bytes
/
persisted_measurement.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package db
import (
"errors"
"github.com/boreq/statuspage-backend/monitor"
)
//go:generate msgp
type PersistedMeasurement struct {
Id string `msg:"id"`
UpdateEvery float64 `msg:"updateEvery"`
Timestamp int64 `msg:"timestamp"`
Duration float64 `msg:"duration"`
Status string `msg:"status"`
Output string `msg:"string"`
}
const (
statusFailure = "failure"
statusUp = "up"
statusDown = "down"
)
func encodeStatus(status monitor.StatusEnum) (string, error) {
switch status {
case monitor.FAILURE:
return statusFailure, nil
case monitor.UP:
return statusUp, nil
case monitor.DOWN:
return statusDown, nil
default:
return "", errors.New("unknown status")
}
}
func decodeStatus(status string) (monitor.StatusEnum, error) {
switch status {
case statusFailure:
return monitor.FAILURE, nil
case statusUp:
return monitor.UP, nil
case statusDown:
return monitor.DOWN, nil
default:
return "", errors.New("unknown status")
}
}