github.com/laof/lite-speed-test@v0.0.0-20230930011949-1f39b7037845/config/resolver.go (about) 1 package config 2 3 import ( 4 "errors" 5 "net" 6 7 "github.com/laof/lite-speed-test/dns" 8 ) 9 10 var defaultResolver *dns.Resolver 11 12 func resolveIP(host string) (string, error) { 13 ipAddr := net.ParseIP(host) 14 if ipAddr != nil { 15 return host, nil 16 } 17 if defaultResolver != nil { 18 ipAddr, err := defaultResolver.ResolveIP(host) 19 if err != nil { 20 return "", err 21 } 22 return ipAddr.String(), nil 23 } 24 return "", errors.New("resolver not found") 25 } 26 27 func init() { 28 defaultResolver = dns.DefaultResolver() 29 // defaultResolver = nil 30 }