소스 검색

use return not use else (#1028)

田欧 8 년 전
부모
커밋
b539606eed
1개의 변경된 파일6개의 추가작업 그리고 4개의 파일을 삭제
  1. 6 4
      auth.go

+ 6 - 4
auth.go

@@ -52,11 +52,13 @@ func BasicAuthForRealm(accounts Accounts, realm string) HandlerFunc {
 			// Credentials doesn't match, we return 401 and abort handlers chain.
 			// Credentials doesn't match, we return 401 and abort handlers chain.
 			c.Header("WWW-Authenticate", realm)
 			c.Header("WWW-Authenticate", realm)
 			c.AbortWithStatus(401)
 			c.AbortWithStatus(401)
-		} else {
-			// The user credentials was found, set user's id to key AuthUserKey in this context, the userId can be read later using
-			// c.MustGet(gin.AuthUserKey)
-			c.Set(AuthUserKey, user)
+			return
 		}
 		}
+
+		// The user credentials was found, set user's id to key AuthUserKey in this context, the user's id can be read later using
+		// c.MustGet(gin.AuthUserKey)
+		c.Set(AuthUserKey, user)
+		return
 	}
 	}
 }
 }