Minor fixes

This commit is contained in:
世界 2022-07-10 14:22:28 +08:00
parent 29f78248dc
commit 7f84191748
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
12 changed files with 69 additions and 39 deletions

View file

@ -161,7 +161,7 @@ type ListenPrefix netip.Prefix
func (p ListenPrefix) MarshalJSON() ([]byte, error) {
prefix := netip.Prefix(p)
if !prefix.IsValid() {
return json.Marshal("")
return json.Marshal(nil)
}
return json.Marshal(prefix.String())
}
@ -179,3 +179,10 @@ func (p *ListenPrefix) UnmarshalJSON(bytes []byte) error {
*p = ListenPrefix(prefix)
return nil
}
func (p *ListenPrefix) Build() netip.Prefix {
if p == nil {
return netip.Prefix{}
}
return netip.Prefix(*p)
}