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 (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Add(hostname string, owner string, description string, publicKey string) {
|
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{}
|
conf := DsnetConfig{}
|
||||||
err = json.Unmarshal(raw, &conf)
|
err = json.Unmarshal(raw, &conf)
|
||||||
check(err)
|
check(err)
|
||||||
|
|
||||||
|
fmt.Printf("%+v\n", conf)
|
||||||
}
|
}
|
||||||
|
15
types.go
15
types.go
@ -4,6 +4,7 @@ import (
|
|||||||
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// see https://github.com/WireGuard/wgctrl-go/blob/master/wgtypes/types.go for definitions
|
// 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
|
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 {
|
func (n *JSONIPNet) String() string {
|
||||||
return n.IPNet.String()
|
return n.IPNet.String()
|
||||||
}
|
}
|
||||||
@ -85,6 +93,13 @@ func (k JSONKey) MarshalJSON() ([]byte, error) {
|
|||||||
return []byte("\"" + k.Key.String() + "\""), nil
|
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 {
|
func GenerateJSONPrivateKey() JSONKey {
|
||||||
privateKey, err := wgtypes.GeneratePrivateKey()
|
privateKey, err := wgtypes.GeneratePrivateKey()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user