-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathclient.go
79 lines (69 loc) · 1.51 KB
/
client.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
71
72
73
74
75
76
77
78
79
package goStrongswanVici
import (
"net"
)
type ClientOptions struct {
Network string
Addr string
// Dialer creates new network connection and has priority over
// Network and Addr options.
Dialer func() (net.Conn, error)
}
type Client struct {
o ClientOptions
}
func NewClient(options ClientOptions) (client *Client) {
if options.Dialer == nil {
options.Dialer = func() (net.Conn, error) {
return net.Dial(options.Network, options.Addr)
}
}
return &Client{
o: options,
}
}
func NewClientFromDefaultSocket() (client *Client) {
return NewClient(ClientOptions{
Network: "unix",
Addr: "/var/run/charon.vici",
})
}
func (c *Client) NewConn() (conn *ClientConn, err error) {
conn1, err := c.o.Dialer()
if err != nil {
return nil, err
}
return NewClientConn(conn1), nil
}
func (c *Client) ListSas(ike string, ike_id string) (sas []map[string]IkeSa, err error) {
conn, err := c.NewConn()
if err != nil {
return nil, err
}
defer conn.Close()
return conn.ListSas(ike, ike_id)
}
func (c *Client) ListAllVpnConnInfo() (list []VpnConnInfo, err error) {
conn, err := c.NewConn()
if err != nil {
return nil, err
}
defer conn.Close()
return conn.ListAllVpnConnInfo()
}
func (c *Client) Version() (out *Version, err error) {
conn, err := c.NewConn()
if err != nil {
return nil, err
}
defer conn.Close()
return conn.Version()
}
func (c *Client) Terminate(r *TerminateRequest) (err error) {
conn, err := c.NewConn()
if err != nil {
return err
}
defer conn.Close()
return conn.Terminate(r)
}