From 047a0dc7be31948551bc87364a6a00cd8cee314b Mon Sep 17 00:00:00 2001 From: Callan Bryant Date: Tue, 27 Oct 2020 21:19:13 +0000 Subject: [PATCH] fix json marshalling of uninitialised JSONIPnet --- exttypes.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/exttypes.go b/exttypes.go index 3d13d1b..85bfd1f 100644 --- a/exttypes.go +++ b/exttypes.go @@ -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 {