fix json marshalling of uninitialised JSONIPnet

This commit is contained in:
Callan Bryant 2020-10-27 21:19:13 +00:00
parent ddb0b4c549
commit 047a0dc7be
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA

View File

@ -12,7 +12,11 @@ type JSONIPNet struct {
}
func (n JSONIPNet) MarshalJSON() ([]byte, error) {
return []byte("\"" + n.IPNet.String() + "\""), nil
if len(n.IPNet.IP) == 0 {
return []byte("\"\""), nil
} else {
return []byte("\"" + n.IPNet.String() + "\""), nil
}
}
func (n *JSONIPNet) UnmarshalJSON(b []byte) error {
@ -36,11 +40,7 @@ func (n *JSONIPNet) UnmarshalJSON(b []byte) error {
}
func (n *JSONIPNet) String() string {
if len(n.IPNet.IP) == 0 {
return "\"\""
} else {
return n.IPNet.String()
}
return n.IPNet.String()
}
type JSONKey struct {