mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-04-04 04:17:36 +03:00
Add dns client
This commit is contained in:
parent
651c4b539a
commit
8a761d7e3b
23 changed files with 582 additions and 145 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue