diff --git a/add.go b/add.go index bb006fb..10dd2fe 100644 --- a/add.go +++ b/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) } diff --git a/types.go b/types.go index c751323..b876114 100644 --- a/types.go +++ b/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()