diff options
| author | Shulhan <ms@kilabit.info> | 2018-09-26 23:48:48 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2018-09-26 23:48:48 +0700 |
| commit | eb8b094baf233e4d9981eafe84b030c80d666310 (patch) | |
| tree | 649451aef4843151f837320012c2e8a882f3de7f | |
| parent | 12a61287b468aecf2cf61bd2f7eb14558586bec6 (diff) | |
| download | pakakeh.go-eb8b094baf233e4d9981eafe84b030c80d666310.tar.xz | |
lib/dns: use debug package
| -rw-r--r-- | lib/dns/dns.go | 1 | ||||
| -rw-r--r-- | lib/dns/dns_test.go | 1 | ||||
| -rw-r--r-- | lib/dns/masterfile.go | 3 | ||||
| -rw-r--r-- | lib/dns/message.go | 11 | ||||
| -rw-r--r-- | lib/dns/tcpclient.go | 5 | ||||
| -rw-r--r-- | lib/dns/udpclient.go | 3 |
6 files changed, 13 insertions, 11 deletions
diff --git a/lib/dns/dns.go b/lib/dns/dns.go index 8fd46e71..81385c1d 100644 --- a/lib/dns/dns.go +++ b/lib/dns/dns.go @@ -63,7 +63,6 @@ var ( var ( // clientTimeout define read and write timeout on client request. clientTimeout = 6 * time.Second - debugLevel = 0 ) type OpCode byte diff --git a/lib/dns/dns_test.go b/lib/dns/dns_test.go index 17940b72..f20f4adc 100644 --- a/lib/dns/dns_test.go +++ b/lib/dns/dns_test.go @@ -179,7 +179,6 @@ func (h *serverHandler) ServeDNS(req *Request) { } func TestMain(m *testing.M) { - debugLevel = 0 log.SetFlags(log.Lmicroseconds) _testHandler = &serverHandler{} diff --git a/lib/dns/masterfile.go b/lib/dns/masterfile.go index 686effea..aa4b0df6 100644 --- a/lib/dns/masterfile.go +++ b/lib/dns/masterfile.go @@ -14,6 +14,7 @@ import ( "time" libbytes "github.com/shuLhan/share/lib/bytes" + "github.com/shuLhan/share/lib/debug" libio "github.com/shuLhan/share/lib/io" libtime "github.com/shuLhan/share/lib/time" ) @@ -1053,7 +1054,7 @@ func (m *master) pack() { msg.Header.ANCount = 0 } - if debugLevel >= 1 { + if debug.Value >= 1 { fmt.Printf("= Header: %+v\n", msg.Header) fmt.Printf(" Question: %s\n", msg.Question) for x := 0; x < len(msg.Answer); x++ { diff --git a/lib/dns/message.go b/lib/dns/message.go index 691cc044..ac9ca32e 100644 --- a/lib/dns/message.go +++ b/lib/dns/message.go @@ -12,6 +12,7 @@ import ( "strings" libbytes "github.com/shuLhan/share/lib/bytes" + "github.com/shuLhan/share/lib/debug" ) // @@ -660,7 +661,7 @@ func (msg *Message) Unpack() (err error) { msg.Answer = append(msg.Answer, rr) } - if debugLevel >= 1 { + if debug.Value >= 1 { log.Printf("msg.Answer: %+v\n", msg.Answer) } @@ -674,7 +675,7 @@ func (msg *Message) Unpack() (err error) { msg.Authority = append(msg.Authority, rr) } - if debugLevel >= 1 { + if debug.Value >= 1 { log.Printf("msg.Authority: %+v\n", msg.Authority) } @@ -688,7 +689,7 @@ func (msg *Message) Unpack() (err error) { msg.Additional = append(msg.Additional, rr) } - if debugLevel >= 1 { + if debug.Value >= 1 { log.Printf("msg.Additional: %+v\n", msg.Additional) } @@ -703,7 +704,7 @@ func (msg *Message) Unpack() (err error) { func (msg *Message) UnpackHeaderQuestion() { _ = msg.Header.unpack(msg.Packet) - if debugLevel >= 1 { + if debug.Value >= 1 { log.Printf("msg.Header: %+v\n", msg.Header) } @@ -713,7 +714,7 @@ func (msg *Message) UnpackHeaderQuestion() { _ = msg.Question.unpack(msg.Packet[sectionHeaderSize:]) - if debugLevel >= 1 { + if debug.Value >= 1 { log.Printf("msg.Question: %s\n", msg.Question) } } diff --git a/lib/dns/tcpclient.go b/lib/dns/tcpclient.go index e3f21bf2..492f5627 100644 --- a/lib/dns/tcpclient.go +++ b/lib/dns/tcpclient.go @@ -9,6 +9,7 @@ import ( "time" libbytes "github.com/shuLhan/share/lib/bytes" + "github.com/shuLhan/share/lib/debug" ) // @@ -147,13 +148,13 @@ func (cl *TCPClient) Recv(msg *Message) (n int, err error) { msg.Packet = append(msg.Packet[:0], msg.Packet[:n]...) - if debugLevel >= 2 { + if debug.Value >= 2 { libbytes.PrintHex(">>> TCP msg.Packet:", msg.Packet, 8) } msg.Packet = append(msg.Packet[:0], msg.Packet[2:]...) - if debugLevel >= 2 { + if debug.Value >= 2 { libbytes.PrintHex(">>> DNS msg.Packet:", msg.Packet, 8) } diff --git a/lib/dns/udpclient.go b/lib/dns/udpclient.go index d883e152..a799c160 100644 --- a/lib/dns/udpclient.go +++ b/lib/dns/udpclient.go @@ -9,6 +9,7 @@ import ( "time" libbytes "github.com/shuLhan/share/lib/bytes" + "github.com/shuLhan/share/lib/debug" ) // @@ -140,7 +141,7 @@ func (cl *UDPClient) Recv(msg *Message) (n int, err error) { msg.Packet = append(msg.Packet[:0], msg.Packet[:n]...) - if debugLevel >= 2 { + if debug.Value >= 2 { libbytes.PrintHex(">>> UDPClient: Recv:", msg.Packet, 8) } |
