var (
dialer = &net.Dialer{}
)
type DnsOverride struct {
Domain string `json:"domain"`
Ip string `json:"ip"`
}
func newTr(overrides []DnsOverride, skipTlsVerify bool) *http.Transport {
tr := &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: skipTlsVerify},
}
if len(overrides) == 0 {
return tr
}
tr.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {
return dialer.DialContext(ctx, network, addr)
}
for _, override := range overrides {
if host == override.Domain {
addr = override.Ip + ":" + port
break
}
}
return dialer.DialContext(ctx, network, addr)
}
return tr
}