From 5a71debc59b0b48e3eba03fa1a7a4480ddee6c06 Mon Sep 17 00:00:00 2001 From: Callan Bryant Date: Wed, 4 Mar 2020 22:49:27 +0000 Subject: [PATCH] working (empty) report generation --- cmd/dsnet.go | 2 +- report.go | 19 +++++++++++-------- reporttypes.go | 10 ++++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/cmd/dsnet.go b/cmd/dsnet.go index a9b1d16..f84bd72 100644 --- a/cmd/dsnet.go +++ b/cmd/dsnet.go @@ -29,7 +29,7 @@ func main() { dsnet.Sync() case "report": - dsnet.report() + dsnet.Report() case "down": dsnet.Down() diff --git a/report.go b/report.go index 9113724..9ca4327 100644 --- a/report.go +++ b/report.go @@ -1,19 +1,22 @@ package dsnet import ( - "net" - - "github.com/vishvananda/netlink" "golang.zx2c4.com/wireguard/wgctrl" - "golang.zx2c4.com/wireguard/wgctrl/wgtypes" ) -func Up() { +func Report() { conf := MustLoadDsnetConfig() - dev, err := wgctrl.Device(conf.InterfaceName) + wg, err := wgctrl.New() check(err) + defer wg.Close() - report := Report(dev, conf) - report.MustSave() + dev, err := wg.Device(conf.InterfaceName) + + if err != nil { + ExitFail("Could not retrieve device '%s' (%v)", conf.InterfaceName, err) + } + + report := GenerateReport(dev, conf) + report.MustSave(conf.ReportFile) } diff --git a/reporttypes.go b/reporttypes.go index ac963b3..001d3f8 100644 --- a/reporttypes.go +++ b/reporttypes.go @@ -1,6 +1,8 @@ package dsnet import ( + "encoding/json" + "io/ioutil" "net" "time" @@ -54,13 +56,13 @@ type DsnetReport struct { Peers []PeerReport } -func Report(*wgtypes.Device, conf *DsnetConfig) DsnetReport { - +func GenerateReport(dev *wgtypes.Device, conf *DsnetConfig) DsnetReport { + return DsnetReport{} } -func (report *DsnetReport) MustSave() { +func (report *DsnetReport) MustSave(filename string) { _json, _ := json.MarshalIndent(report, "", " ") - err := ioutil.WriteFile(CONFIG_FILE, _json, 0644) + err := ioutil.WriteFile(filename, _json, 0644) check(err) }