Spliting complex function parseWifiCells

This commit is contained in:
Philippe Caseiro 2018-09-21 15:42:48 +02:00
parent b34ccd3dee
commit 17487dd7a6
1 changed files with 13 additions and 13 deletions

View File

@ -26,11 +26,19 @@ func NewWifiWithExecutor(exec Executor, wIface string) *Wifi {
return &Wifi{exec, wIface, nil}
}
func (w *Wifi) getEncryption(line string) string {
enc := "unkn"
if strings.Contains(line, "WPA2 PSK") {
enc = "psk"
} else if strings.Contains(line, "none") {
enc = "none"
}
return enc
}
func (w *Wifi) parseWifiCells(stdout string) int {
new := false
mac := ""
ssid := ""
enc := ""
mac, ssid, enc := "", "", ""
for _, line := range strings.Split(strings.TrimSuffix(stdout, "\n"), "\n") {
if strings.HasPrefix(line, "Cell") && new == false {
new = true
@ -41,20 +49,12 @@ func (w *Wifi) parseWifiCells(stdout string) int {
ssid = strings.Trim(ssid, "\"")
}
if strings.Contains(line, "Encryption:") {
if strings.Contains(line, "WPA2 PSK") {
enc = "psk"
} else if strings.Contains(line, "none") {
enc = "none"
} else {
enc = "unkn"
}
enc = w.getEncryption(line)
}
if len(mac) > 0 && len(ssid) > 0 && len(enc) > 0 {
cell := NewWifiCell(ssid, mac, enc)
w.Cells = append(w.Cells, cell)
ssid = ""
mac = ""
enc = ""
ssid, mac, enc = "", "", ""
new = false
}
}