From c4a5be6edf134bd0cf1a737727d072b734416fbd Mon Sep 17 00:00:00 2001 From: hkfires <10558748+hkfires@users.noreply.github.com> Date: Wed, 3 Dec 2025 13:53:18 +0800 Subject: [PATCH] style(amp): standardize log message capitalization --- internal/api/modules/amp/amp.go | 28 ++++++++++--------- internal/api/modules/amp/fallback_handlers.go | 8 +++--- internal/api/modules/amp/routes.go | 8 +++--- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/internal/api/modules/amp/amp.go b/internal/api/modules/amp/amp.go index fac77bfb..78e7aa50 100644 --- a/internal/api/modules/amp/amp.go +++ b/internal/api/modules/amp/amp.go @@ -112,8 +112,8 @@ func (m *AmpModule) Register(ctx modules.Context) error { // If no upstream URL, skip proxy routes but provider aliases are still available if upstreamURL == "" { - log.Debug("Amp upstream proxy disabled (no upstream URL configured)") - log.Debug("Amp provider alias routes registered") + log.Debug("amp upstream proxy disabled (no upstream URL configured)") + log.Debug("amp provider alias routes registered") m.enabled = false return } @@ -139,8 +139,8 @@ func (m *AmpModule) Register(ctx modules.Context) error { handler := proxyHandler(proxy) m.registerManagementRoutes(ctx.Engine, ctx.BaseHandler, handler, settings.RestrictManagementToLocalhost) - log.Infof("Amp upstream proxy enabled for: %s", upstreamURL) - log.Debug("Amp provider alias routes registered") + log.Infof("amp upstream proxy enabled for: %s", upstreamURL) + log.Debug("amp provider alias routes registered") }) return regErr @@ -156,7 +156,7 @@ func (m *AmpModule) getAuthMiddleware(ctx modules.Context) gin.HandlerFunc { return ctx.AuthMiddleware } // Fallback: no authentication (should not happen in production) - log.Warn("Amp module: no auth middleware provided, allowing all requests") + log.Warn("amp module: no auth middleware provided, allowing all requests") return func(c *gin.Context) { c.Next() } @@ -165,23 +165,25 @@ func (m *AmpModule) getAuthMiddleware(ctx modules.Context) gin.HandlerFunc { // OnConfigUpdated handles configuration updates. // Currently requires restart for URL changes (could be enhanced for dynamic updates). func (m *AmpModule) OnConfigUpdated(cfg *config.Config) error { + settings := cfg.AmpCode + // Update model mappings (hot-reload supported) if m.modelMapper != nil { - settings := cfg.AmpCode - log.Infof("amp config updated: reloading %d model mapping(s)", len(settings.ModelMappings)) m.modelMapper.UpdateMappings(settings.ModelMappings) - } else { + if m.enabled { + log.Infof("amp config updated: reloading %d model mapping(s)", len(settings.ModelMappings)) + } + } else if m.enabled { log.Warnf("amp model mapper not initialized, skipping model mapping update") } if !m.enabled { - log.Debug("Amp routing not enabled, skipping other config updates") return nil } - upstreamURL := strings.TrimSpace(cfg.AmpCode.UpstreamURL) + upstreamURL := strings.TrimSpace(settings.UpstreamURL) if upstreamURL == "" { - log.Warn("Amp upstream URL removed from config, restart required to disable") + log.Warn("amp upstream URL removed from config, restart required to disable") return nil } @@ -189,11 +191,11 @@ func (m *AmpModule) OnConfigUpdated(cfg *config.Config) error { if m.secretSource != nil { if ms, ok := m.secretSource.(*MultiSourceSecret); ok { ms.InvalidateCache() - log.Debug("Amp secret cache invalidated due to config update") + log.Debug("amp secret cache invalidated due to config update") } } - log.Debug("Amp config updated (restart required for URL changes)") + log.Debug("amp config updated (restart required for URL changes)") return nil } diff --git a/internal/api/modules/amp/fallback_handlers.go b/internal/api/modules/amp/fallback_handlers.go index 17c60708..69d8ba74 100644 --- a/internal/api/modules/amp/fallback_handlers.go +++ b/internal/api/modules/amp/fallback_handlers.go @@ -48,25 +48,25 @@ func logAmpRouting(routeType AmpRouteType, requestedModel, resolvedModel, provid case RouteTypeLocalProvider: fields["cost"] = "free" fields["source"] = "local_oauth" - log.WithFields(fields).Infof("[AMP] Using local provider for model: %s", requestedModel) + log.WithFields(fields).Infof("[amp] using local provider for model: %s", requestedModel) case RouteTypeModelMapping: fields["cost"] = "free" fields["source"] = "local_oauth" fields["mapping"] = requestedModel + " -> " + resolvedModel - log.WithFields(fields).Infof("[AMP] Model mapped: %s -> %s", requestedModel, resolvedModel) + log.WithFields(fields).Infof("[amp] model mapped: %s -> %s", requestedModel, resolvedModel) case RouteTypeAmpCredits: fields["cost"] = "amp_credits" fields["source"] = "ampcode.com" fields["model_id"] = requestedModel // Explicit model_id for easy config reference - log.WithFields(fields).Warnf("[AMP] Forwarding to ampcode.com (uses Amp credits) - model_id: %s | To use local proxy, add to config: amp-model-mappings: [{from: \"%s\", to: \"\"}]", requestedModel, requestedModel) + log.WithFields(fields).Warnf("[amp] forwarding to ampcode.com (uses amp credits) - model_id: %s | To use local proxy, add to config: amp-model-mappings: [{from: \"%s\", to: \"\"}]", requestedModel, requestedModel) case RouteTypeNoProvider: fields["cost"] = "none" fields["source"] = "error" fields["model_id"] = requestedModel // Explicit model_id for easy config reference - log.WithFields(fields).Warnf("[AMP] No provider available for model_id: %s", requestedModel) + log.WithFields(fields).Warnf("[amp] no provider available for model_id: %s", requestedModel) } } diff --git a/internal/api/modules/amp/routes.go b/internal/api/modules/amp/routes.go index 13a5d959..02f518a1 100644 --- a/internal/api/modules/amp/routes.go +++ b/internal/api/modules/amp/routes.go @@ -37,7 +37,7 @@ func localhostOnlyMiddleware() gin.HandlerFunc { // Parse the IP to handle both IPv4 and IPv6 ip := net.ParseIP(host) if ip == nil { - log.Warnf("Amp management: invalid RemoteAddr %s, denying access", remoteAddr) + log.Warnf("amp management: invalid RemoteAddr %s, denying access", remoteAddr) c.AbortWithStatusJSON(403, gin.H{ "error": "Access denied: management routes restricted to localhost", }) @@ -46,7 +46,7 @@ func localhostOnlyMiddleware() gin.HandlerFunc { // Check if IP is loopback (127.0.0.1 or ::1) if !ip.IsLoopback() { - log.Warnf("Amp management: non-localhost connection from %s attempted access, denying", remoteAddr) + log.Warnf("amp management: non-localhost connection from %s attempted access, denying", remoteAddr) c.AbortWithStatusJSON(403, gin.H{ "error": "Access denied: management routes restricted to localhost", }) @@ -89,9 +89,9 @@ func (m *AmpModule) registerManagementRoutes(engine *gin.Engine, baseHandler *ha // Apply localhost-only restriction if configured if restrictToLocalhost { ampAPI.Use(localhostOnlyMiddleware()) - log.Info("Amp management routes restricted to localhost only (CORS disabled)") + log.Info("amp management routes restricted to localhost only (CORS disabled)") } else { - log.Warn("⚠️ Amp management routes are NOT restricted to localhost - this is insecure!") + log.Warn("amp management routes are NOT restricted to localhost - this is insecure!") } // Management routes - these are proxied directly to Amp upstream