generated from datumforge/go-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
region.go
62 lines (51 loc) · 1.27 KB
/
region.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
50
51
52
53
54
55
56
57
58
59
60
61
62
package enums
import (
"fmt"
"io"
"strings"
)
type Region string
var (
Amer Region = "AMER"
Emea Region = "EMEA"
Apac Region = "APAC"
InvalidRegion Region = "INVALID"
)
// Values returns a slice of strings that represents all the possible values of the Region enum.
// Possible default values are "AMER", "EMEA", and "APAC"
func (Region) Values() (kinds []string) {
for _, s := range []Region{Amer, Emea, Apac} {
kinds = append(kinds, string(s))
}
return
}
// String returns the Region as a string
func (r Region) String() string {
return string(r)
}
// ToRegion returns the database provider enum based on string input
func ToRegion(p string) *Region {
switch p := strings.ToUpper(p); p {
case Amer.String():
return &Amer
case Emea.String():
return &Emea
case Apac.String():
return &Apac
default:
return &InvalidRegion
}
}
// MarshalGQL implement the Marshaler interface for gqlgen
func (r Region) MarshalGQL(w io.Writer) {
_, _ = w.Write([]byte(`"` + r.String() + `"`))
}
// UnmarshalGQL implement the Unmarshaler interface for gqlgen
func (r *Region) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("wrong type for Region, got: %T", v) //nolint:goerr113
}
*r = Region(str)
return nil
}