Aetherance commented on code in PR #3252:
URL: https://github.com/apache/dubbo-go/pull/3252#discussion_r2959127674


##########
cluster/router/condition/dynamic_router.go:
##########
@@ -134,6 +134,44 @@ func (d *DynamicRouter) URL() *common.URL {
        return nil
 }
 
+// SetStaticConfig applies a RouterConfig with string conditions directly, 
bypassing YAML parsing.
+// This is the correct entry point for static (code-configured) rules;
+// Process is designed for dynamic config-center updates that arrive as YAML 
text.
+func (d *DynamicRouter) SetStaticConfig(cfg *global.RouterConfig) {
+       if cfg == nil || len(cfg.Conditions) == 0 {
+               return
+       }
+
+       d.mu.Lock()
+       defer d.mu.Unlock()
+
+       force := cfg.Force != nil && *cfg.Force
+       enable := cfg.Enabled == nil || *cfg.Enabled
+
+       if !enable {
+               d.force, d.enable, d.conditionRouter = force, false, nil
+               return
+       }
+
+       conditionRouters := make([]*StateRouter, 0, len(cfg.Conditions))
+       for _, conditionRule := range cfg.Conditions {
+               url, err := common.NewURL("condition://")
+               if err != nil {
+                       logger.Warnf("[condition router] failed to create 
condition URL: %v", err)
+                       continue
+               }
+               url.AddParam(constant.RuleKey, conditionRule)
+               url.AddParam(constant.ForceKey, strconv.FormatBool(force))
+               conditionRoute, err := NewConditionStateRouter(url)
+               if err != nil {
+                       logger.Warnf("[condition router] failed to parse 
condition rule %q: %v", conditionRule, err)
+                       continue
+               }
+               conditionRouters = append(conditionRouters, conditionRoute)
+       }
+       d.force, d.enable, d.conditionRouter = force, enable, 
stateRouters(conditionRouters)
+}
+
 func (d *DynamicRouter) Process(event *config_center.ConfigChangeEvent) {
        d.mu.Lock()
        defer d.mu.Unlock()

Review Comment:
   已新增注释说明。



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to