-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathlistConns.go
47 lines (37 loc) · 969 Bytes
/
listConns.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
package goStrongswanVici
import (
"fmt"
)
func (c *ClientConn) ListConns(ike string) ([]map[string]IKEConf, error) {
conns := []map[string]IKEConf{}
var eventErr error
var err error
err = c.RegisterEvent("list-conn", func(response map[string]interface{}) {
conn := &map[string]IKEConf{}
err = ConvertFromGeneral(response, conn)
if err != nil {
eventErr = fmt.Errorf("list-conn event error: %v", err)
return
}
conns = append(conns, *conn)
})
if err != nil {
return nil, fmt.Errorf("error registering list-conn event: %v", err)
}
if eventErr != nil {
return nil, eventErr
}
reqMap := map[string]interface{}{}
if ike != "" {
reqMap["ike"] = ike
}
_, err = c.Request("list-conns", reqMap)
if err != nil {
return nil, fmt.Errorf("error requesting list-conns: %v", err)
}
err = c.UnregisterEvent("list-conn")
if err != nil {
return nil, fmt.Errorf("error unregistering list-conns event: %v", err)
}
return conns, nil
}