Add device example

This commit is contained in:
Christian Müller 2019-09-18 11:08:24 +02:00
parent 13e298849f
commit 528fab6eed
2 changed files with 43 additions and 1 deletions

View file

@ -12,3 +12,7 @@ Tested with NetworkManager 1.16.0.
## Backward compatibility
The library should also be compatible with NetworkManager 0.9.8.10.
## Usage
You can find some examples in the [examples](examples) directory.

38
examples/devices.go Normal file
View file

@ -0,0 +1,38 @@
package main
import (
"fmt"
"github.com/Wifx/gonetworkmanager"
"os"
)
func main() {
/* Create new instance of gonetworkmanager */
nm, err := gonetworkmanager.NewNetworkManager()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
/* Get devices */
devices, err := nm.GetPropertyAllDevices()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
/* Show each device path and interface name */
for _, device := range devices {
deviceInterface, err := device.GetPropertyInterface()
if err != nil {
fmt.Println(err.Error())
continue
}
fmt.Println(deviceInterface + " - " + string(device.GetPath()))
}
os.Exit(0)
}