Showing 56 of 81 total issues
Method API.doRequest
has 8 return statements (exceeds 4 allowed). Open
func (api *API) doRequest(req *http.Request) ([]byte, *http.Response, error) {
if api.User != "" && api.Pass != "" {
req.SetBasicAuth(api.User, api.Pass)
}
Method Uchiwa.resultsHandler
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
func (u *Uchiwa) resultsHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodDelete {
http.Error(w, "", http.StatusBadRequest)
return
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
} else if global.Db.Driver != "" && global.Db.Scheme != "" {
global.Auth.Driver = "sql"
} else if len(global.Users) != 0 {
logger.Debug("Loading multiple users from the config")
global.Auth.Driver = "simple"
Method Uchiwa.eventHandler
has a Cognitive Complexity of 23 (exceeds 20 allowed). Consider refactoring. Open
func (u *Uchiwa) eventHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodDelete {
http.Error(w, "", http.StatusBadRequest)
return
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method API.getSlice
has 6 return statements (exceeds 4 allowed). Open
func (api *API) getSlice(ctx context.Context, endpoint string, limit int) ([]interface{}, error) {
var offset int
u, err := url.Parse(fmt.Sprintf("%s/%s", api.URL, endpoint))
if err != nil {
Method Uchiwa.datacenterHandler
has 6 return statements (exceeds 4 allowed). Open
func (u *Uchiwa) datacenterHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet && r.Method != http.MethodHead {
http.Error(w, "", http.StatusBadRequest)
return
}
Function IsCheckSilenced
has 5 return statements (exceeds 4 allowed). Open
func IsCheckSilenced(check, client map[string]interface{}, dc string, silenced []interface{}) (bool, []string) {
var isSilenced bool
var commonSubscriptions, isSilencedBy, subscribers, subscriptions []string
if dc == "" || len(silenced) == 0 {
Method Uchiwa.datacentersHandler
has 5 return statements (exceeds 4 allowed). Open
func (u *Uchiwa) datacentersHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet && r.Method != http.MethodHead {
http.Error(w, "", http.StatusBadRequest)
return
}
Method Uchiwa.eventsHandler
has 5 return statements (exceeds 4 allowed). Open
func (u *Uchiwa) eventsHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet && r.Method != http.MethodHead {
http.Error(w, "", http.StatusBadRequest)
return
}
Method Uchiwa.UpdateClient
has 5 return statements (exceeds 4 allowed). Open
func (u *Uchiwa) UpdateClient(payload interface{}) error {
client, ok := payload.(map[string]interface{})
if !ok {
return fmt.Errorf("Unable to decode the payload")
}
Method Uchiwa.stashesHandler
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
func (u *Uchiwa) stashesHandler(w http.ResponseWriter, r *http.Request) {
token := authentication.GetJWTFromContext(r)
if r.Method == http.MethodGet || r.Method == http.MethodHead {
// GET on /stashes
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method Uchiwa.aggregatesHandler
has 5 return statements (exceeds 4 allowed). Open
func (u *Uchiwa) aggregatesHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet && r.Method != http.MethodHead {
http.Error(w, "", http.StatusBadRequest)
return
}
Method Uchiwa.checksHandler
has 5 return statements (exceeds 4 allowed). Open
func (u *Uchiwa) checksHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet && r.Method != http.MethodHead {
http.Error(w, "", http.StatusBadRequest)
return
}
Method Uchiwa.requestHandler
has 5 return statements (exceeds 4 allowed). Open
func (u *Uchiwa) requestHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "", http.StatusBadRequest)
return
}
Function verifyJWT
has 5 return statements (exceeds 4 allowed). Open
func verifyJWT(tokenString string) (*jwt.Token, error) {
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
// Don't forget to validate the alg is what you expect:
if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
logger.Debugf("Unexpected signing method: %v", token.Header["alg"])
Method API.getSlice
has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring. Open
func (api *API) getSlice(ctx context.Context, endpoint string, limit int) ([]interface{}, error) {
var offset int
u, err := url.Parse(fmt.Sprintf("%s/%s", api.URL, endpoint))
if err != nil {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"