Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
Refactor network interface selection
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbassi committed Jun 7, 2019
1 parent 1b59858 commit e1f3488
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion main.go
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/widgets/net.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit e1f3488

Please sign in to comment.