File size: 1,094 Bytes
1e92f2d |
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 50 51 52 53 54 55 56 57 58 59 60 |
package notice
//go:generate go tool stringer -type Type
import (
"io"
"github.com/99designs/gqlgen/graphql"
"github.com/target/goalert/validation"
)
type Notice struct {
Type Type
Message string
Details string
}
// Type NoticeType represents the level of severity of a Notice.
type Type int
// Defaults to Warning when unset
const (
TypeWarning Type = iota
TypeError
TypeInfo
)
// UnmarshalGQL implements the graphql.Marshaler interface
func (t *Type) UnmarshalGQL(v interface{}) error {
str, err := graphql.UnmarshalString(v)
if err != nil {
return err
}
switch str {
case "WARNING":
*t = TypeWarning
case "ERROR":
*t = TypeError
case "INFO":
*t = TypeInfo
default:
return validation.NewFieldError("Type", "unknown type "+str)
}
return nil
}
// MarshalGQL implements the graphql.Marshaler interface
func (t Type) MarshalGQL(w io.Writer) {
switch t {
case TypeWarning:
graphql.MarshalString("WARNING").MarshalGQL(w)
case TypeError:
graphql.MarshalString("ERROR").MarshalGQL(w)
case TypeInfo:
graphql.MarshalString("INFO").MarshalGQL(w)
}
}
|