From 3bea20850a7042fd7a8b209f509cef78854fc3f0 Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Sun, 14 Aug 2022 12:40:22 +0200 Subject: [PATCH] Some linting fixes --- noise.go | 5 +++-- noise_api.go | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/noise.go b/noise.go index bd7d4bbd..53deae33 100644 --- a/noise.go +++ b/noise.go @@ -113,6 +113,7 @@ func (h *Headscale) getNoiseConnection( if err != nil { log.Error().Caller().Err(err).Msgf("Hijack failed") http.Error(writer, "HTTP does not support general TCP support", http.StatusInternalServerError) + return nil, errCannotHijack } if err := conn.Flush(); err != nil { @@ -123,12 +124,12 @@ func (h *Headscale) getNoiseConnection( netConn = netutil.NewDrainBufConn(netConn, conn.Reader) - nc, err := controlbase.Server(req.Context(), netConn, *h.noisePrivateKey, init) + noiseConn, err := controlbase.Server(req.Context(), netConn, *h.noisePrivateKey, init) if err != nil { netConn.Close() return nil, errNoiseHandshakeFailed } - return nc, nil + return noiseConn, nil } diff --git a/noise_api.go b/noise_api.go index fc0f0911..f20305ca 100644 --- a/noise_api.go +++ b/noise_api.go @@ -22,6 +22,7 @@ func (h *Headscale) NoiseRegistrationHandler( log.Trace().Caller().Msgf("Noise registration handler for client %s", req.RemoteAddr) if req.Method != http.MethodPost { http.Error(writer, "Wrong method", http.StatusMethodNotAllowed) + return } body, _ := io.ReadAll(req.Body) @@ -296,8 +297,8 @@ func (h *Headscale) handleNoiseAuthKey( } func (h *Headscale) handleNoiseNodeValidRegistration( - w http.ResponseWriter, - r *http.Request, + writer http.ResponseWriter, + req *http.Request, machine Machine, ) { resp := tailcfg.RegisterResponse{} @@ -314,9 +315,9 @@ func (h *Headscale) handleNoiseNodeValidRegistration( machineRegistrations.WithLabelValues("update", "web", "success", machine.Namespace.Name). Inc() - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(resp) + writer.Header().Set("Content-Type", "application/json") + writer.WriteHeader(http.StatusOK) + json.NewEncoder(writer).Encode(resp) } func (h *Headscale) handleNoiseMachineRegistrationNew(