Chore: Enable Go linter gocritic (#26224)

* Chore: Enable gocritic linter

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen
2020-07-16 14:39:01 +02:00
committed by GitHub
parent 317c7b269c
commit d4e4cb4c71
43 changed files with 184 additions and 171 deletions
+4 -3
View File
@@ -102,11 +102,12 @@ func SearchDashboardSnapshots(query *models.GetDashboardSnapshotsQuery) error {
}
// admins can see all snapshots, everyone else can only see their own snapshots
if query.SignedInUser.OrgRole == models.ROLE_ADMIN {
switch {
case query.SignedInUser.OrgRole == models.ROLE_ADMIN:
sess.Where("org_id = ?", query.OrgId)
} else if !query.SignedInUser.IsAnonymous {
case !query.SignedInUser.IsAnonymous:
sess.Where("org_id = ? AND user_id = ?", query.OrgId, query.SignedInUser.UserId)
} else {
default:
query.Result = snapshots
return nil
}
+4 -2
View File
@@ -116,7 +116,8 @@ func UpdateOrgQuota(cmd *models.UpdateOrgQuotaCmd) error {
}
} else {
//update existing quota entry in the DB.
if _, err := sess.ID(quota.Id).Update(&quota); err != nil {
_, err := sess.ID(quota.Id).Update(&quota)
if err != nil {
return err
}
}
@@ -218,7 +219,8 @@ func UpdateUserQuota(cmd *models.UpdateUserQuotaCmd) error {
}
} else {
//update existing quota entry in the DB.
if _, err := sess.ID(quota.Id).Update(&quota); err != nil {
_, err := sess.ID(quota.Id).Update(&quota)
if err != nil {
return err
}
}
+6 -3
View File
@@ -8,12 +8,15 @@ func EnsureTagsExist(sess *DBSession, tags []*models.Tag) ([]*models.Tag, error)
var existingTag models.Tag
// check if it exists
if exists, err := sess.Table("tag").Where("`key`=? AND `value`=?", tag.Key, tag.Value).Get(&existingTag); err != nil {
exists, err := sess.Table("tag").Where("`key`=? AND `value`=?", tag.Key, tag.Value).Get(&existingTag)
if err != nil {
return nil, err
} else if exists {
}
if exists {
tag.Id = existingTag.Id
} else {
if _, err := sess.Table("tag").Insert(tag); err != nil {
_, err := sess.Table("tag").Insert(tag)
if err != nil {
return nil, err
}
}
+4 -3
View File
@@ -395,11 +395,12 @@ func GetSignedInUser(query *models.GetSignedInUserQuery) error {
LEFT OUTER JOIN org on org.id = org_user.org_id `
sess := x.Table("user")
if query.UserId > 0 {
switch {
case query.UserId > 0:
sess.SQL(rawSql+"WHERE u.id=?", query.UserId)
} else if query.Login != "" {
case query.Login != "":
sess.SQL(rawSql+"WHERE u.login=?", query.Login)
} else if query.Email != "" {
case query.Email != "":
sess.SQL(rawSql+"WHERE u.email=?", query.Email)
}