Update auth.go
Browse files
auth.go
CHANGED
|
@@ -15,6 +15,7 @@ func APIKeyAuthMiddleware(validKeys map[string]bool) gin.HandlerFunc {
|
|
| 15 |
apiKey := c.GetHeader(APIKeyHeaderName)
|
| 16 |
|
| 17 |
if apiKey == "" {
|
|
|
|
| 18 |
log.Printf("WARN: [%s] API Key missing in header '%s'", c.ClientIP(), APIKeyHeaderName)
|
| 19 |
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
|
| 20 |
"type": "error",
|
|
@@ -27,6 +28,7 @@ func APIKeyAuthMiddleware(validKeys map[string]bool) gin.HandlerFunc {
|
|
| 27 |
}
|
| 28 |
|
| 29 |
if _, isValid := validKeys[apiKey]; !isValid {
|
|
|
|
| 30 |
log.Printf("WARN: [%s] Invalid API Key received (length: %d)", c.ClientIP(), len(apiKey))
|
| 31 |
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
|
| 32 |
"type": "error",
|
|
@@ -38,8 +40,8 @@ func APIKeyAuthMiddleware(validKeys map[string]bool) gin.HandlerFunc {
|
|
| 38 |
return
|
| 39 |
}
|
| 40 |
|
| 41 |
-
//
|
| 42 |
// log.Printf("INFO: [%s] Valid API key received (length: %d)", c.ClientIP(), len(apiKey))
|
| 43 |
c.Next() // Proceed to the next handler
|
| 44 |
}
|
| 45 |
-
}
|
|
|
|
| 15 |
apiKey := c.GetHeader(APIKeyHeaderName)
|
| 16 |
|
| 17 |
if apiKey == "" {
|
| 18 |
+
// Giữ lại: Log cảnh báo quan trọng về thiếu API Key
|
| 19 |
log.Printf("WARN: [%s] API Key missing in header '%s'", c.ClientIP(), APIKeyHeaderName)
|
| 20 |
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
|
| 21 |
"type": "error",
|
|
|
|
| 28 |
}
|
| 29 |
|
| 30 |
if _, isValid := validKeys[apiKey]; !isValid {
|
| 31 |
+
// Giữ lại: Log cảnh báo quan trọng về API Key không hợp lệ
|
| 32 |
log.Printf("WARN: [%s] Invalid API Key received (length: %d)", c.ClientIP(), len(apiKey))
|
| 33 |
c.AbortWithStatusJSON(http.StatusUnauthorized, gin.H{
|
| 34 |
"type": "error",
|
|
|
|
| 40 |
return
|
| 41 |
}
|
| 42 |
|
| 43 |
+
// Đã được comment từ trước, tốt cho việc giảm log không cần thiết
|
| 44 |
// log.Printf("INFO: [%s] Valid API key received (length: %d)", c.ClientIP(), len(apiKey))
|
| 45 |
c.Next() // Proceed to the next handler
|
| 46 |
}
|
| 47 |
+
}
|