mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 21:10:51 +08:00
style(amp): standardize log message capitalization
This commit is contained in:
@@ -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 no upstream URL, skip proxy routes but provider aliases are still available
|
||||||
if upstreamURL == "" {
|
if upstreamURL == "" {
|
||||||
log.Debug("Amp upstream proxy disabled (no upstream URL configured)")
|
log.Debug("amp upstream proxy disabled (no upstream URL configured)")
|
||||||
log.Debug("Amp provider alias routes registered")
|
log.Debug("amp provider alias routes registered")
|
||||||
m.enabled = false
|
m.enabled = false
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -139,8 +139,8 @@ func (m *AmpModule) Register(ctx modules.Context) error {
|
|||||||
handler := proxyHandler(proxy)
|
handler := proxyHandler(proxy)
|
||||||
m.registerManagementRoutes(ctx.Engine, ctx.BaseHandler, handler, settings.RestrictManagementToLocalhost)
|
m.registerManagementRoutes(ctx.Engine, ctx.BaseHandler, handler, settings.RestrictManagementToLocalhost)
|
||||||
|
|
||||||
log.Infof("Amp upstream proxy enabled for: %s", upstreamURL)
|
log.Infof("amp upstream proxy enabled for: %s", upstreamURL)
|
||||||
log.Debug("Amp provider alias routes registered")
|
log.Debug("amp provider alias routes registered")
|
||||||
})
|
})
|
||||||
|
|
||||||
return regErr
|
return regErr
|
||||||
@@ -156,7 +156,7 @@ func (m *AmpModule) getAuthMiddleware(ctx modules.Context) gin.HandlerFunc {
|
|||||||
return ctx.AuthMiddleware
|
return ctx.AuthMiddleware
|
||||||
}
|
}
|
||||||
// Fallback: no authentication (should not happen in production)
|
// 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) {
|
return func(c *gin.Context) {
|
||||||
c.Next()
|
c.Next()
|
||||||
}
|
}
|
||||||
@@ -165,23 +165,25 @@ func (m *AmpModule) getAuthMiddleware(ctx modules.Context) gin.HandlerFunc {
|
|||||||
// OnConfigUpdated handles configuration updates.
|
// OnConfigUpdated handles configuration updates.
|
||||||
// Currently requires restart for URL changes (could be enhanced for dynamic updates).
|
// Currently requires restart for URL changes (could be enhanced for dynamic updates).
|
||||||
func (m *AmpModule) OnConfigUpdated(cfg *config.Config) error {
|
func (m *AmpModule) OnConfigUpdated(cfg *config.Config) error {
|
||||||
|
settings := cfg.AmpCode
|
||||||
|
|
||||||
// Update model mappings (hot-reload supported)
|
// Update model mappings (hot-reload supported)
|
||||||
if m.modelMapper != nil {
|
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)
|
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")
|
log.Warnf("amp model mapper not initialized, skipping model mapping update")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !m.enabled {
|
if !m.enabled {
|
||||||
log.Debug("Amp routing not enabled, skipping other config updates")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
upstreamURL := strings.TrimSpace(cfg.AmpCode.UpstreamURL)
|
upstreamURL := strings.TrimSpace(settings.UpstreamURL)
|
||||||
if 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,11 +191,11 @@ func (m *AmpModule) OnConfigUpdated(cfg *config.Config) error {
|
|||||||
if m.secretSource != nil {
|
if m.secretSource != nil {
|
||||||
if ms, ok := m.secretSource.(*MultiSourceSecret); ok {
|
if ms, ok := m.secretSource.(*MultiSourceSecret); ok {
|
||||||
ms.InvalidateCache()
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -48,25 +48,25 @@ func logAmpRouting(routeType AmpRouteType, requestedModel, resolvedModel, provid
|
|||||||
case RouteTypeLocalProvider:
|
case RouteTypeLocalProvider:
|
||||||
fields["cost"] = "free"
|
fields["cost"] = "free"
|
||||||
fields["source"] = "local_oauth"
|
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:
|
case RouteTypeModelMapping:
|
||||||
fields["cost"] = "free"
|
fields["cost"] = "free"
|
||||||
fields["source"] = "local_oauth"
|
fields["source"] = "local_oauth"
|
||||||
fields["mapping"] = requestedModel + " -> " + resolvedModel
|
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:
|
case RouteTypeAmpCredits:
|
||||||
fields["cost"] = "amp_credits"
|
fields["cost"] = "amp_credits"
|
||||||
fields["source"] = "ampcode.com"
|
fields["source"] = "ampcode.com"
|
||||||
fields["model_id"] = requestedModel // Explicit model_id for easy config reference
|
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: \"<your-local-model>\"}]", 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: \"<your-local-model>\"}]", requestedModel, requestedModel)
|
||||||
|
|
||||||
case RouteTypeNoProvider:
|
case RouteTypeNoProvider:
|
||||||
fields["cost"] = "none"
|
fields["cost"] = "none"
|
||||||
fields["source"] = "error"
|
fields["source"] = "error"
|
||||||
fields["model_id"] = requestedModel // Explicit model_id for easy config reference
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func localhostOnlyMiddleware() gin.HandlerFunc {
|
|||||||
// Parse the IP to handle both IPv4 and IPv6
|
// Parse the IP to handle both IPv4 and IPv6
|
||||||
ip := net.ParseIP(host)
|
ip := net.ParseIP(host)
|
||||||
if ip == nil {
|
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{
|
c.AbortWithStatusJSON(403, gin.H{
|
||||||
"error": "Access denied: management routes restricted to localhost",
|
"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)
|
// Check if IP is loopback (127.0.0.1 or ::1)
|
||||||
if !ip.IsLoopback() {
|
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{
|
c.AbortWithStatusJSON(403, gin.H{
|
||||||
"error": "Access denied: management routes restricted to localhost",
|
"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
|
// Apply localhost-only restriction if configured
|
||||||
if restrictToLocalhost {
|
if restrictToLocalhost {
|
||||||
ampAPI.Use(localhostOnlyMiddleware())
|
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 {
|
} 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
|
// Management routes - these are proxied directly to Amp upstream
|
||||||
|
|||||||
Reference in New Issue
Block a user