-
Notifications
You must be signed in to change notification settings - Fork 10
/
utils.go
48 lines (44 loc) · 1.05 KB
/
utils.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
package conservator
import (
"errors"
"fmt"
)
func (s *Conservator) getService(integrationID int32) (*Service, error) {
// Get the service
si, ok := s.services.Load(integrationID)
if !ok {
return nil, fmt.Errorf("missing integrationID %d", integrationID)
}
service, ok := si.(Service)
if !ok {
return nil, fmt.Errorf("missing integrationID %d", integrationID)
}
return &service, nil
}
func (s *Conservator) getServiceByAddress(address string) (*Service, error) {
var service *Service
s.services.Range(func(ki, vi interface{}) bool {
v := vi.(Service)
if v.Address == address {
service = &v
return false
}
return true
})
if service == nil {
return service, errors.New("server not found")
}
return service, nil
}
func (s *Conservator) getChannel(channelID string) (*Channel, error) {
// Get the service
si, ok := s.channels.Load(channelID)
if !ok {
return nil, fmt.Errorf("missing channelID %s", channelID)
}
channel, ok := si.(Channel)
if !ok {
return nil, fmt.Errorf("missing channelID %s", channelID)
}
return &channel, nil
}