From 1307dca7cfc697ad657ee92cf5bb04dc5c0074c5 Mon Sep 17 00:00:00 2001 From: John Beisley Date: Wed, 9 Dec 2015 21:42:36 +0000 Subject: [PATCH] Add another example showing getting byte transfer counts on igd1. --- example/example_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/example/example_test.go b/example/example_test.go index 6554c65..4cd4219 100644 --- a/example/example_test.go +++ b/example/example_test.go @@ -91,3 +91,30 @@ func Example_ReuseDiscoveredDevice() { } // Output: } + +// Use discovered WANCommonInterfaceConfig1 services to discover byte transfer +// counts. +func Example_WANCommonInterfaceConfig1_GetBytesTransferred() { + clients, errors, err := internetgateway1.NewWANCommonInterfaceConfig1Clients() + if err != nil { + fmt.Fprintln(os.Stderr, "Error discovering service with UPnP:", err) + return + } + fmt.Fprintf(os.Stderr, "Error discovering %d services:\n", len(errors)) + for _, err := range errors { + fmt.Println(" ", err) + } + for _, client := range clients { + if recv, err := client.GetTotalBytesReceived(); err != nil { + fmt.Fprintln(os.Stderr, "Error requesting bytes received:", err) + } else { + fmt.Fprintln(os.Stderr, "Bytes received:", recv) + } + if sent, err := client.GetTotalBytesSent(); err != nil { + fmt.Fprintln(os.Stderr, "Error requesting bytes sent:", err) + } else { + fmt.Fprintln(os.Stderr, "Bytes sent:", sent) + } + } + // Output: +}