Add dns client

This commit is contained in:
世界 2022-07-06 23:11:48 +08:00
parent 651c4b539a
commit 8a761d7e3b
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
23 changed files with 582 additions and 145 deletions

View file

@ -90,3 +90,47 @@ func (l *Listable[T]) UnmarshalJSON(content []byte) error {
*l = []T{singleItem}
return nil
}
type DomainStrategy C.DomainStrategy
func (s DomainStrategy) MarshalJSON() ([]byte, error) {
var value string
switch C.DomainStrategy(s) {
case C.DomainStrategyAsIS:
value = "AsIS"
case C.DomainStrategyPreferIPv4:
value = "PreferIPv4"
case C.DomainStrategyPreferIPv6:
value = "PreferIPv6"
case C.DomainStrategyUseIPv4:
value = "UseIPv4"
case C.DomainStrategyUseIPv6:
value = "UseIPv6"
default:
return nil, E.New("unknown domain strategy: ", s)
}
return json.Marshal(value)
}
func (s *DomainStrategy) UnmarshalJSON(bytes []byte) error {
var value string
err := json.Unmarshal(bytes, &value)
if err != nil {
return err
}
switch value {
case "AsIS":
*s = DomainStrategy(C.DomainStrategyAsIS)
case "PreferIPv4":
*s = DomainStrategy(C.DomainStrategyPreferIPv4)
case "PreferIPv6":
*s = DomainStrategy(C.DomainStrategyPreferIPv6)
case "UseIPv4":
*s = DomainStrategy(C.DomainStrategyUseIPv4)
case "UseIPv6":
*s = DomainStrategy(C.DomainStrategyUseIPv6)
default:
return E.New("unknown domain strategy: ", value)
}
return nil
}