blob: 072fa3e29c2ac2ffaf6fc4d0b92d1c1277f04c89 [file] [log] [blame]
//go:generate stringer -type=Direction
//
package alerts
import "encoding/json"
// Direction a step takes that will cause an alert.
//
// It is an int, but will serialize to/from a string in JSON.
type Direction int
// The values for the Direction enum. Run 'go generate' if you
// add/remove/update these values. You must have 'stringer' installed, i.e.
//
// go get golang.org/x/tools/cmd/stringer
const (
BOTH Direction = iota
UP
DOWN
DIRECTION_EOL // End of list.
)
// UnmarshalJSON will decode invalid values as BOTH.
func (a *Direction) UnmarshalJSON(b []byte) error {
*a = BOTH
var s string
if err := json.Unmarshal(b, &s); err != nil {
return err
}
for i := Direction(0); i < DIRECTION_EOL; i++ {
if Direction(i).String() == s {
*a = i
break
}
}
return nil
}
func (a Direction) MarshalJSON() ([]byte, error) {
return json.Marshal(a.String())
}