From 0f35971118f042a97f36d41aa101201b8dd14601 Mon Sep 17 00:00:00 2001 From: Star Brilliant Date: Sat, 9 Mar 2019 19:05:07 +0800 Subject: [PATCH] Replace Url with URL --- doh-client/google.go | 4 ++-- doh-client/ietf.go | 6 +++--- doh-client/selector/randomSelector.go | 4 ++-- doh-client/selector/upstream.go | 4 ++-- doh-client/selector/weightRoundRobinSelector.go | 16 ++++++++-------- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/doh-client/google.go b/doh-client/google.go index 23e0d9f..2658b6f 100644 --- a/doh-client/google.go +++ b/doh-client/google.go @@ -58,7 +58,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter questionType = strconv.FormatUint(uint64(question.Qtype), 10) } - requestURL := fmt.Sprintf("%s?ct=application/dns-json&name=%s&type=%s", upstream.Url, url.QueryEscape(questionName), url.QueryEscape(questionType)) + requestURL := fmt.Sprintf("%s?ct=application/dns-json&name=%s&type=%s", upstream.URL, url.QueryEscape(questionName), url.QueryEscape(questionType)) if r.CheckingDisabled { requestURL += "&cd=1" @@ -118,7 +118,7 @@ func (c *Client) generateRequestGoogle(ctx context.Context, w dns.ResponseWriter udpSize: udpSize, ednsClientAddress: ednsClientAddress, ednsClientNetmask: ednsClientNetmask, - currentUpstream: upstream.Url, + currentUpstream: upstream.URL, } } diff --git a/doh-client/ietf.go b/doh-client/ietf.go index f68f08f..87d573e 100644 --- a/doh-client/ietf.go +++ b/doh-client/ietf.go @@ -100,7 +100,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter, r.Id = requestID requestBase64 := base64.RawURLEncoding.EncodeToString(requestBinary) - requestURL := fmt.Sprintf("%s?ct=application/dns-message&dns=%s", upstream.Url, requestBase64) + requestURL := fmt.Sprintf("%s?ct=application/dns-message&dns=%s", upstream.URL, requestBase64) var req *http.Request if len(requestURL) < 2048 { @@ -115,7 +115,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter, } } } else { - req, err = http.NewRequest(http.MethodPost, upstream.Url, bytes.NewReader(requestBinary)) + req, err = http.NewRequest(http.MethodPost, upstream.URL, bytes.NewReader(requestBinary)) if err != nil { log.Println(err) reply := jsonDNS.PrepareReply(r) @@ -159,7 +159,7 @@ func (c *Client) generateRequestIETF(ctx context.Context, w dns.ResponseWriter, udpSize: udpSize, ednsClientAddress: ednsClientAddress, ednsClientNetmask: ednsClientNetmask, - currentUpstream: upstream.Url, + currentUpstream: upstream.URL, } } diff --git a/doh-client/selector/randomSelector.go b/doh-client/selector/randomSelector.go index 36eca50..9509845 100644 --- a/doh-client/selector/randomSelector.go +++ b/doh-client/selector/randomSelector.go @@ -23,14 +23,14 @@ func (rs *RandomSelector) Add(url string, upstreamType UpstreamType) (err error) case Google: rs.upstreams = append(rs.upstreams, &Upstream{ Type: Google, - Url: url, + URL: url, RequestType: "application/dns-json", }) case IETF: rs.upstreams = append(rs.upstreams, &Upstream{ Type: IETF, - Url: url, + URL: url, RequestType: "application/dns-message", }) diff --git a/doh-client/selector/upstream.go b/doh-client/selector/upstream.go index e7c8ea0..f01eaba 100644 --- a/doh-client/selector/upstream.go +++ b/doh-client/selector/upstream.go @@ -16,7 +16,7 @@ var typeMap = map[UpstreamType]string{ type Upstream struct { Type UpstreamType - Url string + URL string RequestType string weight int32 effectiveWeight int32 @@ -24,5 +24,5 @@ type Upstream struct { } func (u Upstream) String() string { - return fmt.Sprintf("upstream type: %s, upstream url: %s", typeMap[u.Type], u.Url) + return fmt.Sprintf("upstream type: %s, upstream url: %s", typeMap[u.Type], u.URL) } diff --git a/doh-client/selector/weightRoundRobinSelector.go b/doh-client/selector/weightRoundRobinSelector.go index a0e87c1..947bb99 100644 --- a/doh-client/selector/weightRoundRobinSelector.go +++ b/doh-client/selector/weightRoundRobinSelector.go @@ -24,7 +24,7 @@ func (ws *WeightRoundRobinSelector) Add(url string, upstreamType UpstreamType, w case Google: ws.upstreams = append(ws.upstreams, &Upstream{ Type: Google, - Url: url, + URL: url, RequestType: "application/dns-json", weight: weight, effectiveWeight: weight, @@ -33,7 +33,7 @@ func (ws *WeightRoundRobinSelector) Add(url string, upstreamType UpstreamType, w case IETF: ws.upstreams = append(ws.upstreams, &Upstream{ Type: IETF, - Url: url, + URL: url, RequestType: "application/dns-message", weight: weight, effectiveWeight: weight, @@ -51,27 +51,27 @@ func (ws *WeightRoundRobinSelector) StartEvaluate() { go func() { for { for i := range ws.upstreams { - upstreamUrl := ws.upstreams[i].Url + upstreamURL := ws.upstreams[i].URL var acceptType string switch ws.upstreams[i].Type { case Google: - upstreamUrl += "?name=www.example.com&type=A" + upstreamURL += "?name=www.example.com&type=A" acceptType = "application/dns-json" case IETF: // www.example.com - upstreamUrl += "?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB" + upstreamURL += "?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB" acceptType = "application/dns-message" } - req, err := http.NewRequest(http.MethodGet, upstreamUrl, nil) + req, err := http.NewRequest(http.MethodGet, upstreamURL, nil) if err != nil { - /*log.Println("upstream:", upstreamUrl, "type:", typeMap[upstream.Type], "check failed:", err) + /*log.Println("upstream:", upstreamURL, "type:", typeMap[upstream.Type], "check failed:", err) continue*/ // should I only log it? But if there is an error, I think when query the server will return error too - panic("upstream: " + upstreamUrl + " type: " + typeMap[ws.upstreams[i].Type] + " check failed: " + err.Error()) + panic("upstream: " + upstreamURL + " type: " + typeMap[ws.upstreams[i].Type] + " check failed: " + err.Error()) } req.Header.Set("accept", acceptType)