pkg/middlewares/jwt.go
Method JWT.CheckUpdateNewCred
has a Cognitive Complexity of 43 (exceeds 20 allowed). Consider refactoring. Open
Open
func (j *JWT) CheckUpdateNewCred() error {
for user, data := range j.Users {
if data.NewData != nil {
if data.NewData.Password == data.Password || data.NewData.Secret == data.Secret {
return fmt.Errorf("JWT: new credentials are same as old for user %s", user)
- 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
Function validateSecretAndPass
has a Cognitive Complexity of 39 (exceeds 20 allowed). Consider refactoring. Open
Open
func validateSecretAndPass(secret []string) error {
var length int = 16
var stype string = "password"
for _, s := range secret {
// Check length
- 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
Consider simplifying this complex logical expression. Open
Open
if c >= 32 && c <= 126 && !((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) {
Method JWT.CheckUpdateNewCred
has 12 return statements (exceeds 4 allowed). Open
Open
func (j *JWT) CheckUpdateNewCred() error {
for user, data := range j.Users {
if data.NewData != nil {
if data.NewData.Password == data.Password || data.NewData.Secret == data.Secret {
return fmt.Errorf("JWT: new credentials are same as old for user %s", user)
Method JWT.Authenticate
has 8 return statements (exceeds 4 allowed). Open
Open
func (j *JWT) Authenticate(user string, token string) (string, error) {
var tok *jwt.Token
var err error
ud, ok := j.GetUserData(user)
if ok {
Function validateSecretAndPass
has 6 return statements (exceeds 4 allowed). Open
Open
func validateSecretAndPass(secret []string) error {
var length int = 16
var stype string = "password"
for _, s := range secret {
// Check length
Method JWTMiddleware.LoginHandler
has 5 return statements (exceeds 4 allowed). Open
Open
func (m *JWTMiddleware) LoginHandler(w http.ResponseWriter, r *http.Request) {
user := r.Header.Get("username")
pass := r.Header.Get("password")
if user == "" || pass == "" {
w.WriteHeader(http.StatusUnauthorized)