diff options
author | Ruben Pollan <meskio@sindominio.net> | 2018-01-23 22:30:35 +0100 |
---|---|---|
committer | Ruben Pollan <meskio@sindominio.net> | 2018-01-23 22:30:35 +0100 |
commit | f6d98953b0f31614e708da4993204263dfd8eafe (patch) | |
tree | a55e7fd424a154dab92a1fb0859def8576400e3c /bitmask | |
parent | 78afb3d88fbdc69df9d04505a51b5fa40a2ea37d (diff) |
[feat] add gateway selection
Diffstat (limited to 'bitmask')
-rw-r--r-- | bitmask/vpn.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/bitmask/vpn.go b/bitmask/vpn.go index 9d12f85..7922d6a 100644 --- a/bitmask/vpn.go +++ b/bitmask/vpn.go @@ -1,5 +1,9 @@ package bitmask +import ( + "errors" +) + // StartVPN for provider func (b *Bitmask) StartVPN(provider string) error { _, err := b.send("vpn", "start", provider) @@ -20,3 +24,28 @@ func (b *Bitmask) GetStatus() (string, error) { } 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 +} |