generated from datumforge/go-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
join_policy.go
70 lines (59 loc) · 2.11 KB
/
join_policy.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
63
64
65
66
67
68
69
70
package enums
import (
"fmt"
"io"
"strings"
)
type JoinPolicy string
var (
// JoinPolicyOpen is when the group is open for anyone to join
JoinPolicyOpen JoinPolicy = "OPEN"
// JoinPolicyInviteOnly is when the group is only joinable by invite
JoinPolicyInviteOnly JoinPolicy = "INVITE_ONLY"
// JoinPolicyApplicationOnly is when the group is only joinable by application
JoinPolicyApplicationOnly JoinPolicy = "APPLICATION_ONLY"
// JoinPolicyInviteOrApplication is when the group is joinable by invite or application
JoinPolicyInviteOrApplication JoinPolicy = "INVITE_OR_APPLICATION"
// JoinPolicyInvalid is the default value for the JoinPolicy enum
JoinPolicyInvalid JoinPolicy = "INVALID"
)
// Values returns a slice of strings that represents all the possible values of the JoinPolicy enum.
// Possible default values are "OPEN", "INVITE_ONLY", "APPLICATION_ONLY", and "INVITE_OR_APPLICATION".
func (JoinPolicy) Values() (kinds []string) {
for _, s := range []JoinPolicy{JoinPolicyOpen, JoinPolicyInviteOnly, JoinPolicyApplicationOnly, JoinPolicyInviteOrApplication} {
kinds = append(kinds, string(s))
}
return
}
// String returns the JoinPolicy as a string
func (r JoinPolicy) String() string {
return string(r)
}
// ToGroupJoinPolicy returns the user status enum based on string input
func ToGroupJoinPolicy(r string) *JoinPolicy {
switch r := strings.ToUpper(r); r {
case JoinPolicyOpen.String():
return &JoinPolicyOpen
case JoinPolicyInviteOnly.String():
return &JoinPolicyInviteOnly
case JoinPolicyApplicationOnly.String():
return &JoinPolicyApplicationOnly
case JoinPolicyInviteOrApplication.String():
return &JoinPolicyInviteOrApplication
default:
return &JoinPolicyInvalid
}
}
// MarshalGQL implement the Marshaler interface for gqlgen
func (r JoinPolicy) MarshalGQL(w io.Writer) {
_, _ = w.Write([]byte(`"` + r.String() + `"`))
}
// UnmarshalGQL implement the Unmarshaler interface for gqlgen
func (r *JoinPolicy) UnmarshalGQL(v interface{}) error {
str, ok := v.(string)
if !ok {
return fmt.Errorf("wrong type for JoinPolicy, got: %T", v) //nolint:goerr113
}
*r = JoinPolicy(str)
return nil
}