-
Notifications
You must be signed in to change notification settings - Fork 182
/
server_group.go
45 lines (39 loc) · 980 Bytes
/
server_group.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
package teaconfigs
import (
"github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/rands"
)
type ServerGroup struct {
Id string `yaml:"id" json:"id"`
IsOn bool `yaml:"isOn" json:"isOn"`
Name string `yaml:"name" json:"name"`
ServerIds []string `yaml:"serverIds" json:"serverIds"`
}
func NewServerGroup() *ServerGroup {
return &ServerGroup{
Id: rands.HexString(16),
IsOn: true,
ServerIds: []string{},
}
}
func (this *ServerGroup) Add(serverId ...string) {
for _, id := range serverId {
if lists.ContainsString(this.ServerIds, id) {
continue
}
this.ServerIds = append(this.ServerIds, id)
}
}
func (this *ServerGroup) Remove(serverId string) {
result := []string{}
for _, id := range this.ServerIds {
if id == serverId {
continue
}
result = append(result, id)
}
this.ServerIds = result
}
func (this *ServerGroup) Contains(serverId string) bool {
return lists.ContainsString(this.ServerIds, serverId)
}