github.com/xxf098/lite-proxy@v0.15.1-0.20230422081941-12c69f323218/config/resolver.go (about)

     1  package config
     2  
     3  import (
     4  	"errors"
     5  	"net"
     6  
     7  	"github.com/xxf098/lite-proxy/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  }