diff --git a/CHANGELOG.md b/CHANGELOG.md index b06b04e..6cc6ea8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - ADD: 尝试在核心程序内加入静态页面支持 - CHANGE: 优化日志记录 - CHANGE: 去除部分无用/重复配置 +- CHANGE: 规范化部分函数命名 24w18d --- diff --git a/api/api.go b/api/api.go index 7b3c5f8..7dd56a0 100644 --- a/api/api.go +++ b/api/api.go @@ -17,7 +17,7 @@ var ( var ( logw = logger.Logw logInfo = logger.LogInfo - LogWarning = logger.LogWarning + logWarning = logger.LogWarning logError = logger.LogError ) diff --git a/auth/auth.go b/auth/auth.go index bdb74eb..4f5a80d 100644 --- a/auth/auth.go +++ b/auth/auth.go @@ -11,7 +11,7 @@ import ( var ( logw = logger.Logw logInfo = logger.LogInfo - LogWarning = logger.LogWarning + logWarning = logger.LogWarning logError = logger.LogError ) @@ -38,13 +38,13 @@ func AuthHandler(c *gin.Context, cfg *config.Config) bool { // 验证 token if authToken == "" { - LogWarning("auth FAILED: no auth_token provided") + logWarning("auth FAILED: no auth_token provided") return false } isValid := authToken == cfg.Auth.AuthToken if !isValid { - LogWarning("auth FAILED: invalid auth_token: %s", authToken) + logWarning("auth FAILED: invalid auth_token: %s", authToken) } logInfo("auth SUCCESS: %t", isValid) diff --git a/main.go b/main.go index bb6e278..47f63c1 100644 --- a/main.go +++ b/main.go @@ -26,7 +26,7 @@ var ( var ( logw = logger.Logw logInfo = logger.LogInfo - LogWarning = logger.LogWarning + logWarning = logger.LogWarning logError = logger.LogError ) @@ -83,13 +83,17 @@ func init() { indexPagePath := fmt.Sprintf("%s/index.html", cfg.Pages.StaticDir) faviconPath := fmt.Sprintf("%s/favicon.ico", cfg.Pages.StaticDir) // 静态index页 - router.StaticFile("/", indexPagePath) + //router.StaticFile("/", indexPagePath) + router.GET("/", func(c *gin.Context) { + c.File(indexPagePath) + logInfo("IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto) + }) // 静态favicon.ico router.StaticFile("/favicon.ico", faviconPath) } else if !cfg.Pages.Enabled { router.GET("/", func(c *gin.Context) { c.String(http.StatusForbidden, "403 Forbidden This route is not allowed to access.") - LogWarning("Forbidden: IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto) + logWarning("Forbidden: IP:%s UA:%s METHOD:%s HTTPv:%s", c.ClientIP(), c.Request.UserAgent(), c.Request.Method, c.Request.Proto) }) } diff --git a/proxy/proxy.go b/proxy/proxy.go index 9593dbd..4479af3 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -21,7 +21,7 @@ import ( var ( logw = logger.Logw logInfo = logger.LogInfo - LogWarning = logger.LogWarning + logWarning = logger.LogWarning logError = logger.LogError ) @@ -40,7 +40,7 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { matches := re.FindStringSubmatch(rawPath) if len(matches) < 3 { - LogWarning("Invalid URL: %s", rawPath) + logWarning("Invalid URL: %s", rawPath) c.String(http.StatusForbidden, "Invalid URL.") return } @@ -51,14 +51,14 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { pathmatches := regexp.MustCompile(`^([^/]+)/([^/]+)/([^/]+)/.*`) pathParts := pathmatches.FindStringSubmatch(matches[2]) if len(pathParts) < 4 { - LogWarning("Invalid path: %s", rawPath) + logWarning("Invalid path: %s", rawPath) c.String(http.StatusForbidden, "Invalid path; expected username/repo.") return } username := pathParts[2] repo := pathParts[3] - LogWarning("Blacklist Check > Username: %s, Repo: %s", username, repo) + logWarning("Blacklist Check > Username: %s, Repo: %s", username, repo) fullrepo := fmt.Sprintf("%s/%s", username, repo) // 白名单检查 @@ -67,7 +67,7 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { if !whitelistpass { errMsg := fmt.Sprintf("Whitelist Blocked repo: %s", fullrepo) c.JSON(http.StatusForbidden, gin.H{"error": errMsg}) - LogWarning(errMsg) + logWarning(errMsg) return } } @@ -78,7 +78,7 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { if blacklistpass { errMsg := fmt.Sprintf("Blacklist Blocked repo: %s", fullrepo) c.JSON(http.StatusForbidden, gin.H{"error": errMsg}) - LogWarning(errMsg) + logWarning(errMsg) return } } @@ -95,7 +95,7 @@ func NoRouteHandler(cfg *config.Config) gin.HandlerFunc { if !auth.AuthHandler(c, cfg) { c.AbortWithStatusJSON(401, gin.H{"error": "Unauthorized"}) - LogWarning("Unauthorized request: %s", rawPath) + logWarning("Unauthorized request: %s", rawPath) return } @@ -139,7 +139,7 @@ func ProxyRequest(c *gin.Context, u string, cfg *config.Config, mode string) { defer resp.Body.Close() if err := HandleResponseSize(resp, cfg, c); err != nil { - LogWarning("Error handling response size: %v", err) + logWarning("Error handling response size: %v", err) return } @@ -211,7 +211,7 @@ func HandleResponseSize(resp *req.Response, cfg *config.Config, c *gin.Context) if err == nil && size > cfg.Server.SizeLimit { finalURL := resp.Request.URL.String() c.Redirect(http.StatusMovedPermanently, finalURL) - LogWarning("Size limit exceeded: %s, Size: %d", finalURL, size) + logWarning("Size limit exceeded: %s, Size: %d", finalURL, size) return fmt.Errorf("size limit exceeded: %d", size) } } @@ -268,7 +268,7 @@ func setDefaultHeaders(c *gin.Context) { func HandleError(c *gin.Context, message string) { c.String(http.StatusInternalServerError, fmt.Sprintf("server error %v", message)) - LogWarning(message) + logWarning(message) } func CheckURL(u string) []string { @@ -279,6 +279,6 @@ func CheckURL(u string) []string { } } errMsg := fmt.Sprintf("Invalid URL: %s", u) - LogWarning(errMsg) + logWarning(errMsg) return nil }