feat(watcher): implement incremental client hot-reloading

This commit is contained in:
hkfires
2025-09-03 20:47:43 +08:00
parent 6d2f7e3ce0
commit f60ef0b2e7
3 changed files with 203 additions and 133 deletions

View File

@@ -292,7 +292,8 @@ func corsMiddleware() gin.HandlerFunc {
// Parameters:
// - clients: The new slice of AI service clients
// - cfg: The new application configuration
func (s *Server) UpdateClients(clients []interfaces.Client, cfg *config.Config) {
func (s *Server) UpdateClients(clients map[string]interfaces.Client, cfg *config.Config) {
clientSlice := s.clientsToSlice(clients)
// Update request logger enabled state if it has changed
if s.requestLogger != nil && s.cfg.RequestLog != cfg.RequestLog {
s.requestLogger.SetEnabled(cfg.RequestLog)
@@ -310,11 +311,11 @@ func (s *Server) UpdateClients(clients []interfaces.Client, cfg *config.Config)
}
s.cfg = cfg
s.handlers.UpdateClients(clients, cfg)
s.handlers.UpdateClients(clientSlice, cfg)
if s.mgmt != nil {
s.mgmt.SetConfig(cfg)
}
log.Infof("server clients and configuration updated: %d clients", len(clients))
log.Infof("server clients and configuration updated: %d clients", len(clientSlice))
}
// (management handlers moved to internal/api/handlers/management)
@@ -384,3 +385,11 @@ func AuthMiddleware(cfg *config.Config) gin.HandlerFunc {
c.Next()
}
}
func (s *Server) clientsToSlice(clientMap map[string]interfaces.Client) []interfaces.Client {
slice := make([]interfaces.Client, 0, len(clientMap))
for _, v := range clientMap {
slice = append(slice, v)
}
return slice
}