From 40b93a5b14dae638333bc725eb4016845ff0f28d Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Thu, 1 Apr 2021 17:30:24 +0300 Subject: [PATCH] Make changes in cores and dispatchers based on staticcheck flags --- cores/basic_auth.go | 8 ++++---- cores/core.go | 1 - cores/server.go | 4 ++-- dispatchers/libdispatcher.go | 3 --- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cores/basic_auth.go b/cores/basic_auth.go index 6b47f02af..2ff46aa67 100644 --- a/cores/basic_auth.go +++ b/cores/basic_auth.go @@ -55,28 +55,28 @@ func basicAuth(userList map[string]string) basicAuthMiddleware { authHeader := strings.SplitN(r.Header.Get("Authorization"), " ", 2) if len(authHeader) != 2 { utils.Logger.Warning(" Missing authorization header value") - http.Error(w, "Not authorized", 401) + http.Error(w, "Not authorized", http.StatusUnauthorized) return } authHeaderDecoded, err := base64.StdEncoding.DecodeString(authHeader[1]) if err != nil { utils.Logger.Warning(" Unable to decode authorization header") - http.Error(w, err.Error(), 401) + http.Error(w, err.Error(), http.StatusUnauthorized) return } userPass := strings.SplitN(string(authHeaderDecoded), ":", 2) if len(userPass) != 2 { utils.Logger.Warning(" Unauthorized API access. Missing or extra credential components") - http.Error(w, "Not authorized", 401) + http.Error(w, "Not authorized", http.StatusUnauthorized) return } valid := verifyCredential(userPass[0], userPass[1], userList) if !valid { utils.Logger.Warning(fmt.Sprintf(" Unauthorized API access by user '%s'", userPass[0])) - http.Error(w, "Not authorized", 401) + http.Error(w, "Not authorized", http.StatusUnauthorized) return } diff --git a/cores/core.go b/cores/core.go index 89a1fe7b6..74b561760 100644 --- a/cores/core.go +++ b/cores/core.go @@ -47,7 +47,6 @@ type CoreService struct { func (cS *CoreService) Shutdown() { utils.Logger.Info(fmt.Sprintf("<%s> shutdown initialized", utils.CoreS)) utils.Logger.Info(fmt.Sprintf("<%s> shutdown complete", utils.CoreS)) - return } // Status returns the status of the engine diff --git a/cores/server.go b/cores/server.go index d1d90ee88..6aba1c1af 100644 --- a/cores/server.go +++ b/cores/server.go @@ -83,7 +83,7 @@ func (s *Server) RpcRegisterName(name string, rcvr interface{}) { s.Unlock() } -func (s *Server) RegisterHttpFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) { +func (s *Server) RegisterHTTPFunc(pattern string, handler func(http.ResponseWriter, *http.Request)) { if s.httpMux != nil { s.httpMux.HandleFunc(pattern, handler) } @@ -378,7 +378,7 @@ func loadTLSConfig(serverCrt, serverKey, caCert string, serverPolicy int, } if ok := rootCAs.AppendCertsFromPEM(ca); !ok { - utils.Logger.Crit(fmt.Sprintf("Cannot append certificate authority")) + utils.Logger.Crit("Cannot append certificate authority") return config, errors.New("Cannot append certificate authority") } } diff --git a/dispatchers/libdispatcher.go b/dispatchers/libdispatcher.go index 44317e270..62f388f4b 100644 --- a/dispatchers/libdispatcher.go +++ b/dispatchers/libdispatcher.go @@ -125,7 +125,6 @@ func (wd *WeightDispatcher) SetProfile(pfl *engine.DispatcherProfile) { pfl.Hosts.Sort() wd.hosts = pfl.Hosts.Clone() // avoid concurrency on profile wd.Unlock() - return } // HostIDs used to implement Dispatcher interface @@ -158,7 +157,6 @@ func (d *RandomDispatcher) SetProfile(pfl *engine.DispatcherProfile) { d.Lock() d.hosts = pfl.Hosts.Clone() d.Unlock() - return } // HostIDs used to implement Dispatcher interface @@ -192,7 +190,6 @@ func (d *RoundRobinDispatcher) SetProfile(pfl *engine.DispatcherProfile) { d.Lock() d.hosts = pfl.Hosts.Clone() d.Unlock() - return } // HostIDs used to implement Dispatcher interface