diff --git a/Readme.md b/Readme.md index fed1dfd..668dc6f 100644 --- a/Readme.md +++ b/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 \ No newline at end of file +Easy to use wireguard abstraction for linux +# Used +* github.com/vishvananda/netlink +* golang.zx2c4.com/wireguard/wgctrl \ No newline at end of file diff --git a/devices.go b/devices.go index 09f472d..9bce4eb 100644 --- a/devices.go +++ b/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 } \ No newline at end of file