From 17487dd7a6f4fe2121df40633727ded975b9bbe5 Mon Sep 17 00:00:00 2001 From: Philippe Caseiro Date: Fri, 21 Sep 2018 15:42:48 +0200 Subject: [PATCH] Spliting complex function parseWifiCells --- openwrt/wifi.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/openwrt/wifi.go b/openwrt/wifi.go index d13f5d7..e930bc5 100644 --- a/openwrt/wifi.go +++ b/openwrt/wifi.go @@ -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 } }