From a36ecb2f686833726b1785cf9af3142cc7fe6f54 Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Tue, 30 Oct 2018 09:55:54 +0100 Subject: [PATCH] UciClient attribute needs to be public ... --- uci.go | 10 ++++++++++ uci_dhcp_conf.go | 12 ++++++------ uci_network_interface.go | 14 +++++++------- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/uci.go b/uci.go index f85d0d7..7f9b889 100644 --- a/uci.go +++ b/uci.go @@ -147,3 +147,13 @@ func (u *UCI) GetWifiIfaces() map[int]*UCIWirelessInterface { func (u *UCI) GetWifiDevices() []map[string]string { return u.Wireless.Devices } + +// GetWifiDeviceByName returns a wifi device by his name "radio0" "radio1" +func (u *UCI) GetWifiDeviceByName(name string) map[string]string { + for _, device := range u.Wireless.Devices { + if device["Device"] == name { + return device + } + } + return nil +} diff --git a/uci_dhcp_conf.go b/uci_dhcp_conf.go index cbe2ee9..cf0364c 100644 --- a/uci_dhcp_conf.go +++ b/uci_dhcp_conf.go @@ -9,19 +9,19 @@ type UCIDHCPConf struct { LeaseTime string RangeLimit string StartIP string - uciClient *UCI + UciClient *UCI } // NewUCIDHCPConf builds a new UCIDHCPConf instance func NewUCIDHCPConf(uci *UCI) *UCIDHCPConf { return &UCIDHCPConf{ - uciClient: uci, + UciClient: uci, } } // Create add a new entry for wifi interface in UCI Configuration func (dh *UCIDHCPConf) Create() *Action { - uci := dh.uciClient + uci := dh.UciClient conf := make(map[string]string) conf["name"] = dh.Name @@ -63,7 +63,7 @@ func (dh *UCIDHCPConf) Create() *Action { // Save commit and relaod configuration (writes it to files !) func (dh *UCIDHCPConf) Save() *Action { - uci := dh.uciClient + uci := dh.UciClient commitRes := uci.Commit() if commitRes.ReturnCode != 0 { return commitRes @@ -75,7 +75,7 @@ func (dh *UCIDHCPConf) Save() *Action { // Delete remove wifi interface from UCI Configuration func (dh *UCIDHCPConf) Delete() *Action { - uci := dh.uciClient + uci := dh.UciClient toDelete := fmt.Sprintf("network.%s", dh.Name) del := uci.Delete(toDelete) if del.ReturnCode != 0 { @@ -86,7 +86,7 @@ func (dh *UCIDHCPConf) Delete() *Action { // Update add a new entry for wifi interface in UCI Configuration func (dh *UCIDHCPConf) Update() *Action { - uci := dh.uciClient + uci := dh.UciClient dh.Delete() create := dh.Create() if create.ReturnCode != 0 { diff --git a/uci_network_interface.go b/uci_network_interface.go index 9efbbae..f7904d6 100644 --- a/uci_network_interface.go +++ b/uci_network_interface.go @@ -4,7 +4,7 @@ import "fmt" // UCINetworkInterface describes uci network inteface (uci show network) type UCINetworkInterface struct { - uciClient *UCI + UciClient *UCI Name string Proto string IFName string @@ -19,16 +19,16 @@ type UCINetworkInterface struct { // NewUCINetworkInterface builds a new UCIWirelessConf instance func NewUCINetworkInterface(uci *UCI) *UCINetworkInterface { return &UCINetworkInterface{ - uciClient: uci, + UciClient: uci, DHCP: &UCIDHCPConf{ - uciClient: uci, + UciClient: uci, }, } } // Create add a new entry for wifi interface in UCI Configuration func (ni *UCINetworkInterface) Create() *Action { - uci := ni.uciClient + uci := ni.UciClient conf := make(map[string]string) conf["proto"] = ni.Proto @@ -68,12 +68,12 @@ func (ni *UCINetworkInterface) Create() *Action { // Save commit and relaod configuration (writes it to files !) func (ni *UCINetworkInterface) Save() *Action { - return ni.uciClient.Save() + return ni.UciClient.Save() } // Delete remove wifi interface from UCI Configuration func (ni *UCINetworkInterface) Delete() *Action { - uci := ni.uciClient + uci := ni.UciClient if ni.DHCP.Name != "" { toDelete := fmt.Sprintf("dhcp.%s", ni.Name) @@ -94,7 +94,7 @@ func (ni *UCINetworkInterface) Delete() *Action { // Update add a new entry for wifi interface in UCI Configuration func (ni *UCINetworkInterface) Update() *Action { - uci := ni.uciClient + uci := ni.UciClient ni.Delete() create := ni.Create() if create.ReturnCode != 0 {