mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-05-31 06:44:03 +00:00
Disable logging by default
This commit is contained in:
+2
-1
@@ -31,6 +31,7 @@ func main() {
|
||||
path := flag.String("path", "/resolve", "HTTP path for resolve application")
|
||||
upstream := flag.String("upstream", "8.8.8.8:53,8.8.4.4:53", "Upstream DNS resolver")
|
||||
tcpOnly := flag.Bool("tcp", false, "Only use TCP for DNS query")
|
||||
verbose := flag.Bool("verbose", false, "Enable logging")
|
||||
flag.Parse()
|
||||
|
||||
if (*cert != "") != (*key != "") {
|
||||
@@ -38,7 +39,7 @@ func main() {
|
||||
}
|
||||
|
||||
upstreams := strings.Split(*upstream, ",")
|
||||
server := NewServer(*addr, *cert, *key, *path, upstreams, *tcpOnly)
|
||||
server := NewServer(*addr, *cert, *key, *path, upstreams, *tcpOnly, *verbose)
|
||||
err := server.Start()
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
|
||||
@@ -42,12 +42,13 @@ type Server struct {
|
||||
path string
|
||||
upstreams []string
|
||||
tcpOnly bool
|
||||
verbose bool
|
||||
udpClient *dns.Client
|
||||
tcpClient *dns.Client
|
||||
servemux *http.ServeMux
|
||||
}
|
||||
|
||||
func NewServer(addr, cert, key, path string, upstreams []string, tcpOnly bool) (s *Server) {
|
||||
func NewServer(addr, cert, key, path string, upstreams []string, tcpOnly, verbose bool) (s *Server) {
|
||||
upstreamsCopy := make([]string, len(upstreams))
|
||||
copy(upstreamsCopy, upstreams)
|
||||
s = &Server {
|
||||
@@ -57,6 +58,7 @@ func NewServer(addr, cert, key, path string, upstreams []string, tcpOnly bool) (
|
||||
path: path,
|
||||
upstreams: upstreamsCopy,
|
||||
tcpOnly: tcpOnly,
|
||||
verbose: verbose,
|
||||
udpClient: &dns.Client {
|
||||
Net: "udp",
|
||||
},
|
||||
@@ -70,10 +72,14 @@ func NewServer(addr, cert, key, path string, upstreams []string, tcpOnly bool) (
|
||||
}
|
||||
|
||||
func (s *Server) Start() error {
|
||||
servemux := http.Handler(s.servemux)
|
||||
if s.verbose {
|
||||
servemux = handlers.CombinedLoggingHandler(os.Stdout, servemux)
|
||||
}
|
||||
if s.cert != "" || s.key != "" {
|
||||
return http.ListenAndServeTLS(s.addr, s.cert, s.key, handlers.CombinedLoggingHandler(os.Stdout, s.servemux))
|
||||
return http.ListenAndServeTLS(s.addr, s.cert, s.key, servemux)
|
||||
} else {
|
||||
return http.ListenAndServe(s.addr, handlers.CombinedLoggingHandler(os.Stdout, s.servemux))
|
||||
return http.ListenAndServe(s.addr, servemux)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user