allow empty IPNets

This commit is contained in:
Callan Bryant 2020-10-26 22:47:02 +00:00
parent 555ffad58b
commit 06905db6df
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA

View File

@ -17,6 +17,14 @@ func (n JSONIPNet) MarshalJSON() ([]byte, error) {
func (n *JSONIPNet) UnmarshalJSON(b []byte) error {
cidr := strings.Trim(string(b), "\"")
if cidr == "" {
// Leave as empty/uninitialised IPNet. A bit like omitempty behaviour,
// but we can leave the field there and blank which is useful if the
// user wishes to add the cidr manually.
return nil
}
IP, IPNet, err := net.ParseCIDR(cidr)
if err == nil {