marsevilspirit commented on code in PR #2941:
URL: https://github.com/apache/dubbo-go/pull/2941#discussion_r2221576015


##########
server/options.go:
##########
@@ -948,3 +949,86 @@ func SetProtocols(pros map[string]*global.ProtocolConfig) 
ServiceOption {
                opts.Protocols = pros
        }
 }
+
+func GetProviderOptionsFromConfig(c *global.ServiceConfig) []ServiceOption {
+       var opts []ServiceOption
+
+       if c.Interface != "" {
+               opts = append(opts, WithInterface(c.Interface))
+       }
+       if c.Group != "" {
+               opts = append(opts, WithGroup(c.Group))
+       }
+       if c.Version != "" {
+               opts = append(opts, WithVersion(c.Version))
+       }
+       if c.Serialization != "" {
+               opts = append(opts, WithSerialization(c.Serialization))
+       }
+       if len(c.ProtocolIDs) > 0 {
+               opts = append(opts, WithProtocolIDs(c.ProtocolIDs))
+       }
+       if len(c.RegistryIDs) > 0 {
+               opts = append(opts, WithRegistryIDs(c.RegistryIDs))
+       }
+       if c.Filter != "" {
+               opts = append(opts, WithFilter(c.Filter))
+       }
+       if c.Token != "" {
+               opts = append(opts, WithToken(c.Token))
+       }
+       if c.Tag != "" {
+               opts = append(opts, WithTag(c.Tag))
+       }
+       if c.Cluster != "" {
+               opts = append(opts, WithCluster(c.Cluster))
+       }
+       if c.Loadbalance != "" {
+               opts = append(opts, WithLoadBalance(c.Loadbalance))
+       }
+       if c.Auth != "" {
+               opts = append(opts, WithAuth(c.Auth))
+       }
+       if c.NotRegister {
+               opts = append(opts, WithNotRegister())
+       }
+       if c.ParamSign != "" {
+               opts = append(opts, WithParamSign(c.ParamSign))
+       }
+       if c.Retries != "" {
+               if i, err := strconv.Atoi(c.Retries); err == nil {
+                       opts = append(opts, WithRetries(i))
+               }
+       }
+       if c.ExecuteLimit != "" {
+               opts = append(opts, WithExecuteLimit(c.ExecuteLimit))
+       }
+       if c.TpsLimitRate != "" {
+               if i, err := strconv.Atoi(c.TpsLimitRate); err == nil {
+                       opts = append(opts, WithTpsLimitRate(i))
+               } else {
+                       logger.Warnf("WARN: Failed to parse TpsLimitRate %q: 
%v. TPS limit will not be applied.", c.TpsLimitRate, err)
+               }
+       }
+       if c.TpsLimiter != "" {
+               opts = append(opts, WithTpsLimiter(c.TpsLimiter))
+       }
+       if c.TpsLimitStrategy != "" {
+               opts = append(opts, WithTpsLimitStrategy(c.TpsLimitStrategy))
+       }
+       if c.TpsLimitRejectedHandler != "" {
+               opts = append(opts, 
WithTpsLimitRejectedHandler(c.TpsLimitRejectedHandler))
+       }
+       if c.ExecuteLimitRejectedHandler != "" {
+               opts = append(opts, 
WithExecuteLimitRejectedHandler(c.ExecuteLimitRejectedHandler))
+       }
+       if c.Warmup != "" {
+               if d, err := time.ParseDuration(c.Warmup); err == nil {
+                       opts = append(opts, WithWarmup(d))
+               } else {
+                       logger.Warnf("WARN: Failed to parse Warmup duration %q: 
%v. Warmup period will not be applied.", c.Warmup, err)

Review Comment:
   Same as above.



##########
server/options.go:
##########
@@ -948,3 +949,86 @@ func SetProtocols(pros map[string]*global.ProtocolConfig) 
ServiceOption {
                opts.Protocols = pros
        }
 }
+
+func GetProviderOptionsFromConfig(c *global.ServiceConfig) []ServiceOption {

Review Comment:
   I don't think the solution of this function is correct. I think the reason 
for this problem is the lack of unity of config. We need to carefully consider 
how to simplify and unify config. This function undoubtedly increases the 
complexity of config transmission.



##########
server/options.go:
##########
@@ -948,3 +949,86 @@ func SetProtocols(pros map[string]*global.ProtocolConfig) 
ServiceOption {
                opts.Protocols = pros
        }
 }
+
+func GetProviderOptionsFromConfig(c *global.ServiceConfig) []ServiceOption {
+       var opts []ServiceOption
+
+       if c.Interface != "" {
+               opts = append(opts, WithInterface(c.Interface))
+       }
+       if c.Group != "" {
+               opts = append(opts, WithGroup(c.Group))
+       }
+       if c.Version != "" {
+               opts = append(opts, WithVersion(c.Version))
+       }
+       if c.Serialization != "" {
+               opts = append(opts, WithSerialization(c.Serialization))
+       }
+       if len(c.ProtocolIDs) > 0 {
+               opts = append(opts, WithProtocolIDs(c.ProtocolIDs))
+       }
+       if len(c.RegistryIDs) > 0 {
+               opts = append(opts, WithRegistryIDs(c.RegistryIDs))
+       }
+       if c.Filter != "" {
+               opts = append(opts, WithFilter(c.Filter))
+       }
+       if c.Token != "" {
+               opts = append(opts, WithToken(c.Token))
+       }
+       if c.Tag != "" {
+               opts = append(opts, WithTag(c.Tag))
+       }
+       if c.Cluster != "" {
+               opts = append(opts, WithCluster(c.Cluster))
+       }
+       if c.Loadbalance != "" {
+               opts = append(opts, WithLoadBalance(c.Loadbalance))
+       }
+       if c.Auth != "" {
+               opts = append(opts, WithAuth(c.Auth))
+       }
+       if c.NotRegister {
+               opts = append(opts, WithNotRegister())
+       }
+       if c.ParamSign != "" {
+               opts = append(opts, WithParamSign(c.ParamSign))
+       }
+       if c.Retries != "" {
+               if i, err := strconv.Atoi(c.Retries); err == nil {
+                       opts = append(opts, WithRetries(i))
+               }
+       }
+       if c.ExecuteLimit != "" {
+               opts = append(opts, WithExecuteLimit(c.ExecuteLimit))
+       }
+       if c.TpsLimitRate != "" {
+               if i, err := strconv.Atoi(c.TpsLimitRate); err == nil {
+                       opts = append(opts, WithTpsLimitRate(i))
+               } else {
+                       logger.Warnf("WARN: Failed to parse TpsLimitRate %q: 
%v. TPS limit will not be applied.", c.TpsLimitRate, err)

Review Comment:
   No need to log WARN, Logger.warnf will add WARN auto.



-- 
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: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to