Refactor if/else and switch for the modules package

This commit is contained in:
Edznux 2018-10-23 06:09:10 +02:00
commit 191e8eacff
34 changed files with 326 additions and 199 deletions

View file

@ -84,30 +84,29 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) {
recvd,
seen,
}, include
} else {
// this is ugly, but necessary in order to have this
// method handle both access point and clients
// transparently
clients := ""
if ap, found := w.Session.WiFi.Get(station.HwAddress); found {
if ap.NumClients() > 0 {
clients = strconv.Itoa(ap.NumClients())
}
}
// this is ugly, but necessary in order to have this
// method handle both access point and clients
// transparently
clients := ""
if ap, found := w.Session.WiFi.Get(station.HwAddress); found {
if ap.NumClients() > 0 {
clients = strconv.Itoa(ap.NumClients())
}
return []string{
fmt.Sprintf("%d dBm", station.RSSI),
bssid,
ssid,
/* station.Vendor, */
encryption,
strconv.Itoa(station.Channel()),
clients,
sent,
recvd,
seen,
}, include
}
return []string{
fmt.Sprintf("%d dBm", station.RSSI),
bssid,
ssid,
/* station.Vendor, */
encryption,
strconv.Itoa(station.Channel()),
clients,
sent,
recvd,
seen,
}, include
}
func (w *WiFiModule) Show(by string) error {
@ -123,14 +122,14 @@ func (w *WiFiModule) Show(by string) error {
} else {
stations = w.Session.WiFi.Stations()
}
if by == "seen" {
switch by {
case "seen":
sort.Sort(ByWiFiSeenSorter(stations))
} else if by == "essid" {
case "essid":
sort.Sort(ByEssidSorter(stations))
} else if by == "channel" {
case "channel":
sort.Sort(ByChannelSorter(stations))
} else {
default:
sort.Sort(ByRSSISorter(stations))
}