Fix netip.Prefix usage

This commit is contained in:
世界 2023-10-21 12:00:00 +08:00
parent 41fd1778a7
commit 3b161ab30c
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
7 changed files with 23 additions and 47 deletions

View file

@ -172,34 +172,6 @@ func (d *Duration) UnmarshalJSON(bytes []byte) error {
return nil
}
type ListenPrefix netip.Prefix
func (p ListenPrefix) MarshalJSON() ([]byte, error) {
prefix := netip.Prefix(p)
if !prefix.IsValid() {
return json.Marshal(nil)
}
return json.Marshal(prefix.String())
}
func (p *ListenPrefix) UnmarshalJSON(bytes []byte) error {
var value string
err := json.Unmarshal(bytes, &value)
if err != nil {
return err
}
prefix, err := netip.ParsePrefix(value)
if err != nil {
return err
}
*p = ListenPrefix(prefix)
return nil
}
func (p ListenPrefix) Build() netip.Prefix {
return netip.Prefix(p)
}
type DNSQueryType uint16
func (t DNSQueryType) MarshalJSON() ([]byte, error) {