mirror of
https://github.com/speatzle/nfsense.git
synced 2025-05-10 18:38:22 +00:00
30 lines
447 B
Go
30 lines
447 B
Go
package common
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net"
|
|
)
|
|
|
|
type IPNet struct {
|
|
net.IPNet
|
|
}
|
|
|
|
// MarshalJSON for IPNet
|
|
func (i IPNet) MarshalJSON() ([]byte, error) {
|
|
return json.Marshal(i.String())
|
|
}
|
|
|
|
// UnmarshalJSON for IPNet
|
|
func (i *IPNet) UnmarshalJSON(b []byte) error {
|
|
var s string
|
|
if err := json.Unmarshal(b, &s); err != nil {
|
|
return err
|
|
}
|
|
|
|
_, ipnet, err := net.ParseCIDR(s)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
i.IPNet = *ipnet
|
|
return nil
|
|
}
|