Resolve (some) linter warnings

This commit is contained in:
Star Brilliant
2020-08-02 05:58:24 +08:00
parent 2c7e70466e
commit 4f46b89feb
12 changed files with 80 additions and 79 deletions

View File

@@ -170,11 +170,11 @@ func (s *Server) parseRequestGoogle(ctx context.Context, w http.ResponseWriter,
}
func (s *Server) generateResponseGoogle(ctx context.Context, w http.ResponseWriter, r *http.Request, req *DNSRequest) {
respJSON := jsonDNS.Marshal(req.response)
respJSON := jsondns.Marshal(req.response)
respStr, err := json.Marshal(respJSON)
if err != nil {
log.Println(err)
jsonDNS.FormatError(w, fmt.Sprintf("DNS packet parse failure (%s)", err.Error()), 500)
jsondns.FormatError(w, fmt.Sprintf("DNS packet parse failure (%s)", err.Error()), 500)
return
}

View File

@@ -36,7 +36,7 @@ import (
"strings"
"time"
jsonDNS "github.com/m13253/dns-over-https/json-dns"
jsondns "github.com/m13253/dns-over-https/json-dns"
"github.com/miekg/dns"
)
@@ -156,12 +156,12 @@ func (s *Server) parseRequestIETF(ctx context.Context, w http.ResponseWriter, r
}
func (s *Server) generateResponseIETF(ctx context.Context, w http.ResponseWriter, r *http.Request, req *DNSRequest) {
respJSON := jsonDNS.Marshal(req.response)
respJSON := jsondns.Marshal(req.response)
req.response.Id = req.transactionID
respBytes, err := req.response.Pack()
if err != nil {
log.Printf("DNS packet construct failure with upstream %s: %v\n", req.currentUpstream, err)
jsonDNS.FormatError(w, fmt.Sprintf("DNS packet construct failure (%s)", err.Error()), 500)
jsondns.FormatError(w, fmt.Sprintf("DNS packet construct failure (%s)", err.Error()), 500)
return
}

View File

@@ -35,7 +35,7 @@ import (
"time"
"github.com/gorilla/handlers"
jsonDNS "github.com/m13253/dns-over-https/json-dns"
jsondns "github.com/m13253/dns-over-https/json-dns"
"github.com/miekg/dns"
)
@@ -216,14 +216,14 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
} else if contentType == "application/dns-udpwireformat" {
req = s.parseRequestIETF(ctx, w, r)
} else {
jsonDNS.FormatError(w, fmt.Sprintf("Invalid argument value: \"ct\" = %q", contentType), 415)
jsondns.FormatError(w, fmt.Sprintf("Invalid argument value: \"ct\" = %q", contentType), 415)
return
}
if req.errcode == 444 {
return
}
if req.errcode != 0 {
jsonDNS.FormatError(w, req.errtext, req.errcode)
jsondns.FormatError(w, req.errtext, req.errcode)
return
}
@@ -232,7 +232,7 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
var err error
req, err = s.doDNSQuery(ctx, req)
if err != nil {
jsonDNS.FormatError(w, fmt.Sprintf("DNS query failure (%s)", err.Error()), 503)
jsondns.FormatError(w, fmt.Sprintf("DNS query failure (%s)", err.Error()), 503)
return
}
@@ -256,7 +256,7 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
for _, addr := range strings.Split(XForwardedFor, ",") {
addr = strings.TrimSpace(addr)
ip := net.ParseIP(addr)
if jsonDNS.IsGlobalIP(ip) {
if jsondns.IsGlobalIP(ip) {
return ip
}
}
@@ -265,7 +265,7 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
if XRealIP != "" {
addr := strings.TrimSpace(XRealIP)
ip := net.ParseIP(addr)
if jsonDNS.IsGlobalIP(ip) {
if jsondns.IsGlobalIP(ip) {
return ip
}
}
@@ -273,7 +273,7 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
if err != nil {
return nil
}
if ip := remoteAddr.IP; jsonDNS.IsGlobalIP(ip) {
if ip := remoteAddr.IP; jsondns.IsGlobalIP(ip) {
return ip
}
return nil