Refactor network interface selection

This commit is contained in:
Caleb Bassi 2019-06-07 15:03:00 -07:00
parent 1b5985860c
commit e1f3488c4c
2 changed files with 7 additions and 2 deletions

View File

@ -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

View File

@ -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
}