-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.go
44 lines (39 loc) · 1.17 KB
/
interface.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
package gowrt
import (
"encoding/json"
"fmt"
)
type InterfaceConfiguration struct {
Index int `json:".index"`
Name string `json:".name"`
Device string `json:"device"`
Proto string `json:"proto"`
Username string `json:"username"`
Password string `json:"password"`
Ipv6 string `json:"ipv6"` // "0"
Ip6Assign string `json:"ip6assign"` // 60 set only on "lan"
// IpAddrs []string `json:"ipaddr"`
ReqAddress string `json:"reqaddress"`
ReqPrefix string `json:"reqprefix"`
}
func (c *Client) GetInterfaceConfiguration(name string) (InterfaceConfiguration, error) {
params := map[string]interface{}{
"config": "network",
"type": "interface",
}
call := NewRpcCall("call", "uci", "get", params)
response, err := c.ApiCall(call)
if err != nil {
return InterfaceConfiguration{}, err
}
var interfaces map[string]map[string]InterfaceConfiguration
if err := json.Unmarshal(response, &interfaces); err != nil {
return InterfaceConfiguration{}, err
}
if values, ok := interfaces["values"]; ok {
if iface, ifok := values[name]; ifok {
return iface, nil
}
}
return InterfaceConfiguration{}, fmt.Errorf("interface %s not found", name)
}