From 29ed6389b405aa650e600ca7e3d62ba7ca2a188b Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Thu, 9 Aug 2018 10:08:21 +0800 Subject: [PATCH] go fmt --- cf_httpdns_test.go | 38 +++++++------- cloudflare_httpdns.go | 118 +++++++++++++++++++++--------------------- 2 files changed, 78 insertions(+), 78 deletions(-) diff --git a/cf_httpdns_test.go b/cf_httpdns_test.go index 9bedf61..56e83e9 100644 --- a/cf_httpdns_test.go +++ b/cf_httpdns_test.go @@ -1,19 +1,19 @@ -package main - -import ( - "fmt" - "testing" - - "github.com/miekg/dns" -) - -func TestCFDns(t *testing.T) { - cf := &CloudflareHTTPDns{} - m := new(dns.Msg) - m.SetQuestion("www.google.com.", dns.TypeA) - m1, _, err := cf.Exchange(m, "1.1.1.1") - if err != nil { - t.Fatal(err) - } - fmt.Println(m1.String()) -} +package main + +import ( + "fmt" + "testing" + + "github.com/miekg/dns" +) + +func TestCFDns(t *testing.T) { + cf := &CloudflareHTTPDns{} + m := new(dns.Msg) + m.SetQuestion("www.google.com.", dns.TypeA) + m1, _, err := cf.Exchange(m, "1.1.1.1") + if err != nil { + t.Fatal(err) + } + fmt.Println(m1.String()) +} diff --git a/cloudflare_httpdns.go b/cloudflare_httpdns.go index 5148e2e..9d24837 100644 --- a/cloudflare_httpdns.go +++ b/cloudflare_httpdns.go @@ -1,59 +1,59 @@ -package main - -import ( - "bytes" - "crypto/tls" - "fmt" - "io/ioutil" - "net/http" - "time" - - "github.com/miekg/dns" -) - -var httpclientCF = &http.Client{ - Timeout: 8 * time.Second, - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{ServerName: "cloudflare-dns.com"}, - TLSHandshakeTimeout: 5 * time.Second, - }, -} - -// CloudflareHTTPDns cloudflare http dns -type CloudflareHTTPDns struct { -} - -// Exchange send request to server and get result -func (cf *CloudflareHTTPDns) Exchange(m *dns.Msg, addr string) (m1 *dns.Msg, d time.Duration, err error) { - u := fmt.Sprintf("https://%s/dns-query", addr) - data, err := m.Pack() - if err != nil { - return - } - - body := bytes.NewBuffer(data) - - req, err := http.NewRequest("POST", u, body) - if err != nil { - return - } - - req.Header.Set("Content-Type", "application/dns-udpwireformat") - - resp, err := httpclientCF.Do(req) - if err != nil { - return - } - defer resp.Body.Close() - - data, err = ioutil.ReadAll(resp.Body) - if err != nil { - return - } - - m1 = new(dns.Msg) - if err = m1.Unpack(data); err != nil { - return - } - return -} +package main + +import ( + "bytes" + "crypto/tls" + "fmt" + "io/ioutil" + "net/http" + "time" + + "github.com/miekg/dns" +) + +var httpclientCF = &http.Client{ + Timeout: 8 * time.Second, + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ServerName: "cloudflare-dns.com"}, + TLSHandshakeTimeout: 5 * time.Second, + }, +} + +// CloudflareHTTPDns cloudflare http dns +type CloudflareHTTPDns struct { +} + +// Exchange send request to server and get result +func (cf *CloudflareHTTPDns) Exchange(m *dns.Msg, addr string) (m1 *dns.Msg, d time.Duration, err error) { + u := fmt.Sprintf("https://%s/dns-query", addr) + data, err := m.Pack() + if err != nil { + return + } + + body := bytes.NewBuffer(data) + + req, err := http.NewRequest("POST", u, body) + if err != nil { + return + } + + req.Header.Set("Content-Type", "application/dns-udpwireformat") + + resp, err := httpclientCF.Do(req) + if err != nil { + return + } + defer resp.Body.Close() + + data, err = ioutil.ReadAll(resp.Body) + if err != nil { + return + } + + m1 = new(dns.Msg) + if err = m1.Unpack(data); err != nil { + return + } + return +}