File size: 3,871 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
package assignment
//go:generate go tool stringer -type TargetType
import (
"encoding"
"io"
"github.com/99designs/gqlgen/graphql"
"github.com/target/goalert/validation"
)
// TargetType represents the destination type of an assignment
type TargetType int
// Assignment destination types
const (
TargetTypeUnspecified TargetType = iota
TargetTypeEscalationPolicy
TargetTypeNotificationPolicy
TargetTypeRotation
TargetTypeService
TargetTypeSchedule
TargetTypeCalendarSubscription
TargetTypeUser
TargetTypeNotificationChannel
TargetTypeSlackChannel
TargetTypeSlackUserGroup
TargetTypeChanWebhook
TargetTypeIntegrationKey
TargetTypeUserOverride
TargetTypeNotificationRule
TargetTypeContactMethod
TargetTypeHeartbeatMonitor
TargetTypeUserSession
)
var (
_ graphql.Marshaler = TargetType(0)
_ graphql.Unmarshaler = new(TargetType)
_ encoding.TextMarshaler = TargetType(0)
_ encoding.TextUnmarshaler = new(TargetType)
)
func (tt *TargetType) UnmarshalText(data []byte) error {
str := string(data)
switch str {
case "escalationPolicy":
*tt = TargetTypeEscalationPolicy
case "notificationPolicy":
*tt = TargetTypeNotificationPolicy
case "rotation":
*tt = TargetTypeRotation
case "service":
*tt = TargetTypeService
case "schedule":
*tt = TargetTypeSchedule
case "calendarSubscription":
*tt = TargetTypeCalendarSubscription
case "user":
*tt = TargetTypeUser
case "integrationKey":
*tt = TargetTypeIntegrationKey
case "notificationChannel":
*tt = TargetTypeNotificationChannel
case "slackChannel":
*tt = TargetTypeSlackChannel
case "slackUserGroup":
*tt = TargetTypeSlackUserGroup
case "chanWebhook":
*tt = TargetTypeChanWebhook
case "userOverride":
*tt = TargetTypeUserOverride
case "contactMethod":
*tt = TargetTypeContactMethod
case "notificationRule":
*tt = TargetTypeNotificationRule
case "heartbeatMonitor":
*tt = TargetTypeHeartbeatMonitor
case "userSession":
*tt = TargetTypeUserSession
default:
return validation.NewFieldError("TargetType", "unknown target type "+str)
}
return nil
}
// UnmarshalGQL implements the graphql.Unmarshaler interface
func (tt *TargetType) UnmarshalGQL(v interface{}) error {
str, err := graphql.UnmarshalString(v)
if err != nil {
return err
}
return tt.UnmarshalText([]byte(str))
}
func (tt TargetType) MarshalText() ([]byte, error) {
switch tt {
case TargetTypeEscalationPolicy:
return []byte("escalationPolicy"), nil
case TargetTypeNotificationPolicy:
return []byte("notificationPolicy"), nil
case TargetTypeRotation:
return []byte("rotation"), nil
case TargetTypeService:
return []byte("service"), nil
case TargetTypeSchedule:
return []byte("schedule"), nil
case TargetTypeCalendarSubscription:
return []byte("calendarSubscription"), nil
case TargetTypeUser:
return []byte("user"), nil
case TargetTypeIntegrationKey:
return []byte("integrationKey"), nil
case TargetTypeUserOverride:
return []byte("userOverride"), nil
case TargetTypeNotificationChannel:
return []byte("notificationChannel"), nil
case TargetTypeSlackChannel:
return []byte("slackChannel"), nil
case TargetTypeSlackUserGroup:
return []byte("slackUserGroup"), nil
case TargetTypeChanWebhook:
return []byte("chanWebhook"), nil
case TargetTypeContactMethod:
return []byte("contactMethod"), nil
case TargetTypeNotificationRule:
return []byte("notificationRule"), nil
case TargetTypeHeartbeatMonitor:
return []byte("heartbeatMonitor"), nil
case TargetTypeUserSession:
return []byte("userSession"), nil
}
return nil, validation.NewFieldError("TargetType", "unknown target type "+tt.String())
}
// MarshalGQL implements the graphql.Marshaler interface
func (tt TargetType) MarshalGQL(w io.Writer) {
data, err := tt.MarshalText()
if err != nil {
panic(err)
}
graphql.MarshalString(string(data)).MarshalGQL(w)
}
|