From 4a66022d5054c1dcbadc45fdb69e0ecc98626e23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20S=C3=A4nger?= Date: Tue, 7 Feb 2017 06:07:58 +0100 Subject: [PATCH] use net.JoinHostPort() --- resolver.go | 5 +++-- server.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/resolver.go b/resolver.go index a641f13..2cac6bd 100644 --- a/resolver.go +++ b/resolver.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "net" "strings" "sync" "time" @@ -93,9 +94,9 @@ func (r *Resolver) Lookup(net string, req *dns.Msg) (message *dns.Msg, err error func (r *Resolver) Nameservers() (ns []string) { for _, server := range r.config.Servers { if i := strings.IndexByte(server, '#'); i > 0 { - server = server[:i] + ":" + server[i+1:] + server = net.JoinHostPort(server[:i], server[i+1:]) } else { - server = server + ":" + r.config.Port + server = net.JoinHostPort(server, r.config.Port) } ns = append(ns, server) } diff --git a/server.go b/server.go index 25d6b00..4b8fab0 100644 --- a/server.go +++ b/server.go @@ -1,6 +1,7 @@ package main import ( + "net" "strconv" "time" @@ -15,11 +16,10 @@ type Server struct { } func (s *Server) Addr() string { - return s.host + ":" + strconv.Itoa(s.port) + return net.JoinHostPort(s.host, strconv.Itoa(s.port)) } func (s *Server) Run() { - Handler := NewHandler() tcpHandler := dns.NewServeMux()