summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaleb Bassi <calebjbassi@gmail.com>2019-06-07 15:03:00 -0700
committerCaleb Bassi <calebjbassi@gmail.com>2019-06-07 15:03:00 -0700
commite1f3488c4cb3a15dc95d5d2c32b8727fea9ddff2 (patch)
treecd32681ace6e3a1f54ea1e03fbea42561dfb612e
parent1b5985860ce89d636c883222edd0f233ce4c3f27 (diff)
Refactor network interface selection
-rw-r--r--main.go2
-rw-r--r--src/widgets/net.go7
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
}