mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-16 21:59:53 +05:00
Make changes in cores and dispatchers based on staticcheck flags
This commit is contained in:
committed by
Dan Christian Bogos
parent
7e09dfc6da
commit
40b93a5b14
@@ -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("<BasicAuth> 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("<BasicAuth> 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("<BasicAuth> 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("<BasicAuth> Unauthorized API access by user '%s'", userPass[0]))
|
||||
http.Error(w, "Not authorized", 401)
|
||||
http.Error(w, "Not authorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user