-
Notifications
You must be signed in to change notification settings - Fork 10
/
audience.go
66 lines (54 loc) · 1.11 KB
/
audience.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
package jpush
type Audience struct {
IsAll bool
Value map[string][]string
}
func NewAudience() *Audience {
return &Audience{
Value: make(map[string][]string),
}
}
func (a *Audience) Interface() interface{} {
if a.IsAll {
return "all"
}
return a.Value
}
func (a *Audience) All() *Audience {
a.IsAll = true
return a
}
func (a *Audience) SetTag(tags ...string) *Audience {
a.set("tag", tags)
return a
}
func (a *Audience) SetTagAnd(tagAnds ...string) *Audience {
a.set("tag_and", tagAnds)
return a
}
func (a *Audience) SetTagNot(tagNots ...string) *Audience {
a.set("tag_not", tagNots)
return a
}
func (a *Audience) SetRegistrationId(regIds ...string) *Audience {
a.set("registration_id", regIds)
return a
}
func (a *Audience) SetSegment(segments ...string) *Audience {
a.set("segment", segments)
return a
}
func (a *Audience) SetAbtest(abtests ...string) *Audience {
a.set("abtest", abtests)
return a
}
func (a *Audience) SetAlias(alias ...string) *Audience {
a.set("alias", alias)
return a
}
func (a *Audience) set(key string, v []string) {
if len(v) > 0 {
a.IsAll = false
a.Value[key] = v
}
}