Skip to content

Commit

Permalink
Add device example
Browse files Browse the repository at this point in the history
  • Loading branch information
mullerch committed Sep 18, 2019
1 parent 13e2988 commit 528fab6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ Tested with NetworkManager 1.16.0.

## 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 changes: 38 additions & 0 deletions examples/devices.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 528fab6

Please sign in to comment.