From 2c3bb656126b514a710cbd0ae57ee484dd18ea18 Mon Sep 17 00:00:00 2001 From: Callan Bryant Date: Sun, 1 Mar 2020 23:48:02 +0000 Subject: [PATCH] error() check --- README.md | 10 +++++----- types.go | 8 ++------ util.go | 7 +++++++ 3 files changed, 14 insertions(+), 11 deletions(-) create mode 100644 util.go diff --git a/README.md b/README.md index dc24533..1359040 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ helper. Creates the config file /etc/dsnet.json defining subnet, creating private key, etc. -`dsnet up` +`dsnet sync` Loads peers from JSON file /etc/dsnet.json and brings the interface online. If interface is already online, synchronises peers by adding/removing. Interface name in file, dsnet. Runs commands to add routes/forwarding/whatever. @@ -20,9 +20,9 @@ name in file, dsnet. Runs commands to add routes/forwarding/whatever. Brings the interface down after disassociating all peers. `dsnet add` -Add a peer by name. Returns a config file as QR code or file. If public key is -specified, private key won't be generated. Editing/removing a peer can be done -by editing the JSON file. +Add a peer by name. Returns a config file as QR code or file as specified. If +public key is specified, private key won't be generated. Editing/removing a +peer can be done by editing the JSON file. QR code + confirmation prompt on stderr, peer info on stdout. @@ -36,4 +36,4 @@ etc. The JSON is intended to be consumed by a hugo template as a data source. Could also be updated via XHR/websockets. Report is intended to be generated every minute by cron running as root. The -webserver can then read the file. Location /var/lib/dsnet-info.json +webserver can then read the file. Location /var/lib/dsnet-report.json diff --git a/types.go b/types.go index d9d14fd..c751323 100644 --- a/types.go +++ b/types.go @@ -88,9 +88,7 @@ func (k JSONKey) MarshalJSON() ([]byte, error) { func GenerateJSONPrivateKey() JSONKey { privateKey, err := wgtypes.GeneratePrivateKey() - if err != nil { - panic(err) - } + check(err) return JSONKey{ Key: privateKey, @@ -100,9 +98,7 @@ func GenerateJSONPrivateKey() JSONKey { func GenerateJSONKey() JSONKey { privateKey, err := wgtypes.GenerateKey() - if err != nil { - panic(err) - } + check(err) return JSONKey{ Key: privateKey, diff --git a/util.go b/util.go new file mode 100644 index 0000000..a551dda --- /dev/null +++ b/util.go @@ -0,0 +1,7 @@ +package dsnet + +func check(e error) { + if e != nil { + panic(e) + } +}