forked from arienmalec/alexa-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
confirmationstatus.go
46 lines (40 loc) · 1.26 KB
/
confirmationstatus.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
package alexa
import "strings"
// ConfirmationStatus represents confirmationStatus in JSON
type ConfirmationStatus int
const (
// ConfirmationStatusUndefined means incoming value incorrect or not supported
ConfirmationStatusUndefined ConfirmationStatus = iota
// ConfirmationStatusNone is constant `NONE`
ConfirmationStatusNone
// ConfirmationStatusConfirmed is constant `CONFIRMED`
ConfirmationStatusConfirmed
// ConfirmationStatusDenied is constant `DENIED`
ConfirmationStatusDenied
)
// PropTypes for use outside this module
var confirmationStatusStrings = [...]string{
"Undefined", // Placeholder - should never be this
"NONE",
"CONFIRMED",
"DENIED",
}
// MarshalJSON Function to handle JSON parsing out
func (s ConfirmationStatus) MarshalJSON() ([]byte, error) {
j := string(`"` + confirmationStatusStrings[s] + `"`)
return []byte(j), nil
}
// UnmarshalJSON Function to handle JSON parsing out
func (s *ConfirmationStatus) UnmarshalJSON(data []byte) error {
cs := ConfirmationStatusUndefined
// Convert to string whilst removing quotes
d := string(data)[1 : len(data)-1]
// Find the type in the range of values
for i, s := range confirmationStatusStrings {
if strings.ToLower(s) == strings.ToLower(d) {
cs = ConfirmationStatus(i)
}
}
*s = cs
return nil
}