Add device example
This commit is contained in:
parent
13e298849f
commit
528fab6eed
2 changed files with 43 additions and 1 deletions
|
@ -11,4 +11,8 @@ Tested with NetworkManager 1.16.0.
|
||||||
|
|
||||||
## Backward compatibility
|
## Backward compatibility
|
||||||
|
|
||||||
The library should also be compatible with NetworkManager 0.9.8.10.
|
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
38
examples/devices.go
Normal 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)
|
||||||
|
}
|
Reference in a new issue