From c722edf5342c3a6763f5f38711e4e0126d118df1 Mon Sep 17 00:00:00 2001 From: Alessandro Puccetti Date: Sat, 3 Sep 2016 00:02:38 +0200 Subject: [PATCH] plugins/traffic-control: export trafficControlStatus Rename trafficControlStatus to TrafficControlStatus, because lint complains. --- examples/plugins/traffic-control/main.go | 18 ++++++++++-------- examples/plugins/traffic-control/tc.go | 8 ++++---- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/plugins/traffic-control/main.go b/examples/plugins/traffic-control/main.go index 0abbea057..2f456adf1 100644 --- a/examples/plugins/traffic-control/main.go +++ b/examples/plugins/traffic-control/main.go @@ -51,20 +51,21 @@ type Plugin struct { clients []containerClient } -type trafficControlStatus struct { +// TrafficControlStatus keeps track of parameters status +type TrafficControlStatus struct { latency string packetLoss string } // String is useful to easily create a string of the traffic control plugin internal status. // Useful for debugging -func (tcs *trafficControlStatus) String() string { +func (tcs *TrafficControlStatus) String() string { return fmt.Sprintf("%s %s", tcs.latency, tcs.packetLoss) } // SetLatency sets the latency value // the convention is that empty latency is represented by '-' -func (tcs *trafficControlStatus) SetLatency(latency string) { +func (tcs *TrafficControlStatus) SetLatency(latency string) { if latency == "" { tcs.latency = "-" } @@ -73,7 +74,7 @@ func (tcs *trafficControlStatus) SetLatency(latency string) { // SetPacketLoss sets the packet loss value // the convention is that empty packet loss is represented by '-' -func (tcs *trafficControlStatus) SetPacketLoss(packetLoss string) { +func (tcs *TrafficControlStatus) SetPacketLoss(packetLoss string) { if packetLoss == "" { tcs.packetLoss = "-" } @@ -81,14 +82,15 @@ func (tcs *trafficControlStatus) SetPacketLoss(packetLoss string) { } // TrafficControlStatusInit initializes with the convention that empty values are '-' -func TrafficControlStatusInit() *trafficControlStatus { - return &trafficControlStatus{ +func TrafficControlStatusInit() *TrafficControlStatus { + return &TrafficControlStatus{ latency: "-", packetLoss: "-", } } -var trafficControlStatusCache map[string]*trafficControlStatus +// TrafficControlStatusCache implements status caching +var trafficControlStatusCache map[string]*TrafficControlStatus func main() { const socket = "/var/run/scope/plugins/traffic-control.sock" @@ -105,7 +107,7 @@ func main() { if err != nil { log.Fatalf("Failed to create a plugin: %v", err) } - trafficControlStatusCache = make(map[string]*trafficControlStatus) + trafficControlStatusCache = make(map[string]*TrafficControlStatus) if err := plugin.Serve(listener); err != nil { log.Fatalf("failed to serve: %v", err) } diff --git a/examples/plugins/traffic-control/tc.go b/examples/plugins/traffic-control/tc.go index 1845ccc1d..2f9bf684c 100644 --- a/examples/plugins/traffic-control/tc.go +++ b/examples/plugins/traffic-control/tc.go @@ -125,7 +125,7 @@ func ClearTrafficControlSettings(pid int) error { } func getLatency(pid int) (string, error) { - var status *trafficControlStatus + var status *TrafficControlStatus var err error if status, err = getStatus(pid); err != nil { return "-", err @@ -136,7 +136,7 @@ func getLatency(pid int) (string, error) { } func getPacketLoss(pid int) (string, error) { - var status *trafficControlStatus + var status *TrafficControlStatus var err error if status, err = getStatus(pid); err != nil { return "-", err @@ -146,7 +146,7 @@ func getPacketLoss(pid int) (string, error) { return status.packetLoss, nil } -func getStatus(pid int) (*trafficControlStatus, error) { +func getStatus(pid int) (*TrafficControlStatus, error) { netNS := fmt.Sprintf("/proc/%d/ns/net", pid) netNSID, err := getNSID(netNS) if err != nil { @@ -169,7 +169,7 @@ func getStatus(pid int) (*trafficControlStatus, error) { return nil }) // cache parameters - trafficControlStatusCache[netNSID] = &trafficControlStatus{ + trafficControlStatusCache[netNSID] = &TrafficControlStatus{ latency: parseLatency(output), packetLoss: parsePacketLoss(output), }