| 20 | } |
| 21 | |
| 22 | func NewUpstreamResolver(upstream string, dialer *net.Dialer) *UpstreamResolver { |
| 23 | return &UpstreamResolver{ |
| 24 | r: &net.Resolver{ |
| 25 | PreferGo: true, |
| 26 | Dial: func(ctx context.Context, network, address string) (net.Conn, error) { |
| 27 | // Redirect all Resolver dials to the upstream. |
| 28 | return dialer.DialContext(ctx, network, net.JoinHostPort(upstream, "53")) |
| 29 | }, |
| 30 | }, |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | func (u *UpstreamResolver) Resolve(ctx context.Context, name string) (context.Context, net.IP, error) { |
| 35 | log.Println("Redirected DNS lookup:", name) |