blob: 9886de27547f1d4e91de2487830440aa286c0ef8 [file] [log] [blame]
Serge Bazanskicc25bdf2018-10-25 14:02:58 +02001// +build go1.9
2
3/*
4 *
5 * Copyright 2018 gRPC authors.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 */
20
21package dns
22
23import (
24 "net"
25
26 "golang.org/x/net/context"
27)
28
29var (
30 defaultResolver netResolver = net.DefaultResolver
31)
32
33const defaultDNSSvrPort = "53"
34
35var customAuthorityDialler = func(authority string) func(ctx context.Context, network, address string) (net.Conn, error) {
36 return func(ctx context.Context, network, address string) (net.Conn, error) {
37 var dialer net.Dialer
38 return dialer.DialContext(ctx, network, authority)
39 }
40}
41
42var customAuthorityResolver = func(authority string) (netResolver, error) {
43 host, port, err := parseTarget(authority, defaultDNSSvrPort)
44 if err != nil {
45 return nil, err
46 }
47
48 authorityWithPort := net.JoinHostPort(host, port)
49
50 return &net.Resolver{
51 PreferGo: true,
52 Dial: customAuthorityDialler(authorityWithPort),
53 }, nil
54}