Add another example showing getting byte transfer counts on igd1.
This commit is contained in:
parent
90f71cb5dd
commit
1307dca7cf
@ -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:
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user