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
|
package bitmask
import (
"errors"
)
// StartVPN for provider
func (b *Bitmask) StartVPN(provider string) error {
_, err := b.send("vpn", "start", provider)
return err
}
// StopVPN or cancel
func (b *Bitmask) StopVPN() error {
_, err := b.send("vpn", "stop")
return err
}
// GetStatus returns the VPN status
func (b *Bitmask) GetStatus() (string, error) {
res, err := b.send("vpn", "status")
if err != nil {
return "", err
}
return res["status"].(string), nil
}
// ListGateways return the names of the gateways
func (b *Bitmask) ListGateways(provider string) ([]string, error) {
res, err := b.send("vpn", "list")
if err != nil {
return nil, err
}
names := []string{}
locations, ok := res[provider].([]interface{})
if !ok {
return nil, errors.New("Can't read the locations for provider " + provider)
}
for i := range locations {
loc := locations[i].(map[string]interface{})
names = append(names, loc["name"].(string))
}
return names, nil
}
// UseGateway selects name as the default gateway
func (b *Bitmask) UseGateway(name string) error {
_, err := b.send("vpn", "locations", name)
return err
}
|