Device List

This commit is contained in:
Kekskurse 2021-05-14 16:56:17 +02:00
parent 347b902cf0
commit 13742efcf5
Signed by: kekskurse
GPG Key ID: 728ACCB59341E7E4
2 changed files with 38 additions and 14 deletions

View File

@ -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

View File

@ -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
}