UciClient attribute needs to be public ...

This commit is contained in:
Philippe Caseiro 2018-10-30 09:55:54 +01:00
parent 5912ec7202
commit a36ecb2f68
3 changed files with 23 additions and 13 deletions

10
uci.go
View File

@ -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
}

View File

@ -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 {

View File

@ -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 {