add resolver for cmd

This commit is contained in:
ginuerzh
2022-01-18 23:54:59 +08:00
parent 24971091e3
commit a0ee8bc45c
11 changed files with 373 additions and 26 deletions

View File

@ -71,6 +71,8 @@ type exchanger struct {
}
// NewExchanger create an Exchanger.
// The addr should be URL-like format,
// e.g. udp://1.1.1.1:53, tls://1.1.1.1:853, https://1.0.0.1/dns-query
func NewExchanger(addr string, opts ...Option) (Exchanger, error) {
var options Options
for _, opt := range opts {
@ -85,6 +87,10 @@ func NewExchanger(addr string, opts ...Option) (Exchanger, error) {
return nil, err
}
if options.timeout <= 0 {
options.timeout = 5 * time.Second
}
ex := &exchanger{
network: u.Scheme,
addr: u.Host,