mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 18:11:28 +00:00
28 lines
469 B
Go
28 lines
469 B
Go
package option
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/netip"
|
|
)
|
|
|
|
type ListenAddress netip.Addr
|
|
|
|
func (a *ListenAddress) MarshalJSON() ([]byte, error) {
|
|
value := netip.Addr(*a).String()
|
|
return json.Marshal(value)
|
|
}
|
|
|
|
func (a *ListenAddress) UnmarshalJSON(bytes []byte) error {
|
|
var value string
|
|
err := json.Unmarshal(bytes, &value)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
addr, err := netip.ParseAddr(value)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*a = ListenAddress(addr)
|
|
return nil
|
|
}
|