From e1f3488c4cb3a15dc95d5d2c32b8727fea9ddff2 Mon Sep 17 00:00:00 2001 From: Caleb Bassi Date: Fri, 7 Jun 2019 15:03:00 -0700 Subject: [PATCH] Refactor network interface selection --- main.go | 2 +- src/widgets/net.go | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 4ed0231..c29b9a0 100644 --- a/main.go +++ b/main.go @@ -47,7 +47,7 @@ var ( tempScale = w.Celcius battery = false statusbar = false - netInterface = "all" + netInterface = w.NET_INTERFACE_ALL cpu *w.CpuWidget batt *w.BatteryWidget diff --git a/src/widgets/net.go b/src/widgets/net.go index b4b4a34..3042a10 100644 --- a/src/widgets/net.go +++ b/src/widgets/net.go @@ -11,6 +11,11 @@ import ( "github.com/cjbassi/gotop/src/utils" ) +const ( + NET_INTERFACE_ALL = "all" + NET_INTERFACE_VPN = "tun0" +) + type NetInterface string type NetWidget struct { @@ -65,7 +70,7 @@ func (self *NetWidget) update() { var totalBytesSent uint64 for _, _interface := range interfaces { // ignore VPN interface or filter interface by name - if (_interface.Name != "tun0" && self.NetInterface == "all") || (_interface.Name == self.NetInterface) { + if ((self.NetInterface == NET_INTERFACE_ALL) && (_interface.Name != NET_INTERFACE_VPN)) || (_interface.Name == self.NetInterface) { totalBytesRecv += _interface.BytesRecv totalBytesSent += _interface.BytesSent }