working (empty) report generation
This commit is contained in:
parent
e7fe33fe76
commit
5a71debc59
@ -29,7 +29,7 @@ func main() {
|
||||
dsnet.Sync()
|
||||
|
||||
case "report":
|
||||
dsnet.report()
|
||||
dsnet.Report()
|
||||
|
||||
case "down":
|
||||
dsnet.Down()
|
||||
|
19
report.go
19
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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user