Device List
This commit is contained in:
parent
347b902cf0
commit
13742efcf5
2 changed files with 38 additions and 14 deletions
15
Readme.md
15
Readme.md
|
@ -1,11 +1,4 @@
|
|||
#GoWgPKG
|
||||
|
||||
git.keks.cloud/kekskurse/gowgpkg
|
||||
|
||||
Go Package to configure Wireguard on Linux
|
||||
|
||||
* Create Devices
|
||||
* Configure Device
|
||||
* Create Wireguard
|
||||
* Configure wireguard
|
||||
* Provides Structs with all needed information
|
||||
Easy to use wireguard abstraction for linux
|
||||
# Used
|
||||
* github.com/vishvananda/netlink
|
||||
* golang.zx2c4.com/wireguard/wgctrl
|
37
devices.go
37
devices.go
|
@ -3,13 +3,18 @@ package gowgpkg
|
|||
import (
|
||||
"fmt"
|
||||
"golang.zx2c4.com/wireguard/wgctrl"
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
"github.com/vishvananda/netlink"
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
|
||||
Name string
|
||||
PublicKey string
|
||||
PrivateKey string
|
||||
ListenPort int
|
||||
}
|
||||
|
||||
func ListDevices() ([]Device, error) {
|
||||
func DevicesList() ([]Device, error) {
|
||||
client, err := wgctrl.New()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Can't create wgctrl Client: %w", err)
|
||||
|
@ -22,5 +27,31 @@ func ListDevices() ([]Device, error) {
|
|||
|
||||
fmt.Println(devices)
|
||||
|
||||
return nil, nil
|
||||
var devList []Device
|
||||
|
||||
for _, d := range devices {
|
||||
dev, err := convertToDevice(d)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Cant convertt wgtypes device to gowgpkg device: %w", err)
|
||||
}
|
||||
devList = append(devList, dev)
|
||||
}
|
||||
|
||||
return devList, nil
|
||||
}
|
||||
|
||||
func DevicesCreate(device Device) (error) {
|
||||
// Create IP Device
|
||||
la := netlink.NewLinkAttrs()
|
||||
la.Name = device.Name
|
||||
}
|
||||
|
||||
func convertToDevice(device *wgtypes.Device) (Device, error) {
|
||||
d := Device{}
|
||||
d.Name = device.Name
|
||||
d.PublicKey = device.PublicKey.String()
|
||||
d.PrivateKey = device.PrivateKey.String()
|
||||
d.ListenPort = device.ListenPort
|
||||
|
||||
return d, nil
|
||||
}
|
Loading…
Reference in a new issue