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 Easy to use wireguard abstraction for linux
# Used
git.keks.cloud/kekskurse/gowgpkg * github.com/vishvananda/netlink
* golang.zx2c4.com/wireguard/wgctrl
Go Package to configure Wireguard on Linux
* Create Devices
* Configure Device
* Create Wireguard
* Configure wireguard
* Provides Structs with all needed information

View file

@ -3,13 +3,18 @@ package gowgpkg
import ( import (
"fmt" "fmt"
"golang.zx2c4.com/wireguard/wgctrl" "golang.zx2c4.com/wireguard/wgctrl"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"github.com/vishvananda/netlink"
) )
type Device struct { type Device struct {
Name string
PublicKey string
PrivateKey string
ListenPort int
} }
func ListDevices() ([]Device, error) { func DevicesList() ([]Device, error) {
client, err := wgctrl.New() client, err := wgctrl.New()
if err != nil { if err != nil {
return nil, fmt.Errorf("Can't create wgctrl Client: %w", err) return nil, fmt.Errorf("Can't create wgctrl Client: %w", err)
@ -22,5 +27,31 @@ func ListDevices() ([]Device, error) {
fmt.Println(devices) 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
} }