diff --git a/README.md b/README.md index b55d75b..1cc4d42 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,8 @@ Tested with NetworkManager 1.16.0. ## Backward compatibility -The library should also be compatible with NetworkManager 0.9.8.10. \ No newline at end of file +The library should also be compatible with NetworkManager 0.9.8.10. + +## Usage + +You can find some examples in the [examples](examples) directory. diff --git a/examples/devices.go b/examples/devices.go new file mode 100644 index 0000000..4266142 --- /dev/null +++ b/examples/devices.go @@ -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) +}