Spliting "complex" methods to please go linter !
This commit is contained in:
parent
de0255fd03
commit
ec26c74ae8
|
@ -32,9 +32,7 @@ func (n *Network) ListInterfaces() []net.Interface {
|
|||
fmt.Print(fmt.Errorf("error listing network interfacess: %+v", err.Error()))
|
||||
return nil
|
||||
}
|
||||
for _, i := range ifaces {
|
||||
result = append(result, i)
|
||||
}
|
||||
result = append(result, ifaces...)
|
||||
return result
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,7 @@ func (u *UCI) Commit() *Action {
|
|||
func (u *UCI) Reload() *Action {
|
||||
cmdResult := u.exec.Run("reload_config")
|
||||
|
||||
time.Sleep(5)
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
return &Action{cmdResult}
|
||||
}
|
||||
|
|
|
@ -26,28 +26,12 @@ func NewWifiWithExecutor(exec Executor, wIface string) *Wifi {
|
|||
return &Wifi{exec, wIface, nil}
|
||||
}
|
||||
|
||||
// GetWifiCells retrieves all availabe wifi cells for a card !
|
||||
func (w *Wifi) GetWifiCells() int {
|
||||
res := w.exec.Run("iwinfo", w.iface, "scan")
|
||||
if res.ReturnCode != 0 {
|
||||
log.Fatal(res.Stderr)
|
||||
return res.ReturnCode
|
||||
}
|
||||
|
||||
for res.Stdout == "Scanning not possible" {
|
||||
time.Sleep(1)
|
||||
res = w.exec.Run("iwinfo", w.iface, "scan")
|
||||
if res.ReturnCode != 0 {
|
||||
log.Fatal(res.Stderr)
|
||||
return res.ReturnCode
|
||||
}
|
||||
}
|
||||
|
||||
func (w *Wifi) parseWifiCells(stdout string) int {
|
||||
new := false
|
||||
mac := ""
|
||||
ssid := ""
|
||||
enc := ""
|
||||
for _, line := range strings.Split(strings.TrimSuffix(res.Stdout, "\n"), "\n") {
|
||||
for _, line := range strings.Split(strings.TrimSuffix(stdout, "\n"), "\n") {
|
||||
if strings.HasPrefix(line, "Cell") && new == false {
|
||||
new = true
|
||||
mac = strings.Split(line, " ")[4]
|
||||
|
@ -77,6 +61,25 @@ func (w *Wifi) GetWifiCells() int {
|
|||
return 0
|
||||
}
|
||||
|
||||
// GetWifiCells retrieves all availabe wifi cells for a card !
|
||||
func (w *Wifi) GetWifiCells() int {
|
||||
res := w.exec.Run("iwinfo", w.iface, "scan")
|
||||
if res.ReturnCode != 0 {
|
||||
log.Fatal(res.Stderr)
|
||||
return res.ReturnCode
|
||||
}
|
||||
|
||||
for res.Stdout == "Scanning not possible" {
|
||||
time.Sleep(time.Second)
|
||||
res = w.exec.Run("iwinfo", w.iface, "scan")
|
||||
if res.ReturnCode != 0 {
|
||||
log.Fatal(res.Stderr)
|
||||
return res.ReturnCode
|
||||
}
|
||||
}
|
||||
return w.parseWifiCells(res.Stdout)
|
||||
}
|
||||
|
||||
// GetCell retreives an WifiCell by SSID provided in parameter
|
||||
func (w *Wifi) GetCell(ssid string) *WifiCell {
|
||||
for _, v := range w.Cells {
|
||||
|
|
|
@ -18,17 +18,7 @@ func NewWifiCell(ssid string, mac string, encrypt string) *WifiCell {
|
|||
}
|
||||
}
|
||||
|
||||
// Connect to wifi Cell
|
||||
func (cell *WifiCell) Connect(uci *UCI, secret string) *Action {
|
||||
delRes := uci.Delete("wireless.@wifi-iface[1]")
|
||||
if delRes.ReturnCode != 0 {
|
||||
return delRes
|
||||
}
|
||||
addRes := uci.AddWireless("wifi-iface")
|
||||
if addRes.ReturnCode != 0 {
|
||||
return addRes
|
||||
}
|
||||
|
||||
func (cell *WifiCell) uciWifiConfigure(uci *UCI, secret string) *Action {
|
||||
setRes := uci.Set("wireless.@wifi-iface[1].network", "PyxisNetwork")
|
||||
if setRes.ReturnCode != 0 {
|
||||
return setRes
|
||||
|
@ -58,15 +48,41 @@ func (cell *WifiCell) Connect(uci *UCI, secret string) *Action {
|
|||
if setRes.ReturnCode != 0 {
|
||||
return setRes
|
||||
}
|
||||
setRes = uci.Commit()
|
||||
if setRes.ReturnCode != 0 {
|
||||
return setRes
|
||||
}
|
||||
setRes = uci.Reload()
|
||||
if setRes.ReturnCode != 0 {
|
||||
return setRes
|
||||
}
|
||||
time.Sleep(20)
|
||||
|
||||
return &Action{
|
||||
&CommandResult{
|
||||
Stdout: "",
|
||||
Stderr: "",
|
||||
ReturnCode: 0,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Connect to wifi Cell
|
||||
func (cell *WifiCell) Connect(uci *UCI, secret string) *Action {
|
||||
delRes := uci.Delete("wireless.@wifi-iface[1]")
|
||||
if delRes.ReturnCode != 0 {
|
||||
return delRes
|
||||
}
|
||||
addRes := uci.AddWireless("wifi-iface")
|
||||
if addRes.ReturnCode != 0 {
|
||||
return addRes
|
||||
}
|
||||
|
||||
setRes := cell.uciWifiConfigure(uci, secret)
|
||||
if setRes.ReturnCode != 0 {
|
||||
return setRes
|
||||
}
|
||||
|
||||
setRes = uci.Commit()
|
||||
if setRes.ReturnCode != 0 {
|
||||
return setRes
|
||||
}
|
||||
setRes = uci.Reload()
|
||||
if setRes.ReturnCode != 0 {
|
||||
return setRes
|
||||
}
|
||||
time.Sleep(20 * time.Second)
|
||||
return &Action{
|
||||
&CommandResult{
|
||||
Stdout: "",
|
||||
|
|
Reference in New Issue