broken config file parsing
This commit is contained in:
parent
3cce9fa63e
commit
11a4ab4fc0
3
add.go
3
add.go
@ -3,6 +3,7 @@ package dsnet
|
||||
import (
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func Add(hostname string, owner string, description string, publicKey string) {
|
||||
@ -11,4 +12,6 @@ func Add(hostname string, owner string, description string, publicKey string) {
|
||||
conf := DsnetConfig{}
|
||||
err = json.Unmarshal(raw, &conf)
|
||||
check(err)
|
||||
|
||||
fmt.Printf("%+v\n", conf)
|
||||
}
|
||||
|
15
types.go
15
types.go
@ -4,6 +4,7 @@ import (
|
||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||
"net"
|
||||
"time"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// see https://github.com/WireGuard/wgctrl-go/blob/master/wgtypes/types.go for definitions
|
||||
@ -73,6 +74,13 @@ func (n JSONIPNet) MarshalJSON() ([]byte, error) {
|
||||
return []byte("\"" + n.IPNet.String() + "\""), nil
|
||||
}
|
||||
|
||||
func (n JSONIPNet) UnmarshalJSON(b []byte) error {
|
||||
cidr := strings.Trim(string(b), "\"")
|
||||
_, IPNet, err := net.ParseCIDR(cidr)
|
||||
n.IPNet = *IPNet
|
||||
return err
|
||||
}
|
||||
|
||||
func (n *JSONIPNet) String() string {
|
||||
return n.IPNet.String()
|
||||
}
|
||||
@ -85,6 +93,13 @@ func (k JSONKey) MarshalJSON() ([]byte, error) {
|
||||
return []byte("\"" + k.Key.String() + "\""), nil
|
||||
}
|
||||
|
||||
func (k JSONKey) UnmarshalJSON(b []byte) error {
|
||||
b64Key := strings.Trim(string(b), "\"")
|
||||
key, err := wgtypes.ParseKey(b64Key)
|
||||
k.Key = key
|
||||
return err
|
||||
}
|
||||
|
||||
func GenerateJSONPrivateKey() JSONKey {
|
||||
privateKey, err := wgtypes.GeneratePrivateKey()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user