You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/01/26 09:01:13 UTC

[GitHub] [dubbo-go] LaurenceLiZhixin opened a new pull request #1020: Ftr/configAPI: Add an "api way" to set general configue.

LaurenceLiZhixin opened a new pull request #1020:
URL: https://github.com/apache/dubbo-go/pull/1020


   <!--  Thanks for sending a pull request!
   Read https://github.com/apache/dubbo-go/blob/master/contributing.md before commit pull request. 
   -->
   
   **What this PR does**:
   This pr add an "API way" to set general configure.
   Usage can be found at my branch: 
   https://github.com/LaurenceLiZhixin/dubbo-go-samples/blob/ftr/samples-add/config-api/go-client/cmd/client.go
   or in test file
   
   **Which issue(s) this PR fixes**:
   <!--
   *Automatically closes linked issue when PR is merged.
   Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
   _If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
   -->
   Fixes #
   
   **Special notes for your reviewer**:
   
   **Does this PR introduce a user-facing change?**:
   <!--
   If no, just write "NONE" in the release-note block below.
   If yes, a release note is required:
   Enter your extended release note in the block below. If the PR requires additional action from users switching to the new release, include the string "action required".
   -->
   ```release-note
   
   ```


----------------------------------------------------------------
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.

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



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


[GitHub] [dubbo-go] AlexStocks merged pull request #1020: Ftr: Add an "api way" to set general configure

Posted by GitBox <gi...@apache.org>.
AlexStocks merged pull request #1020:
URL: https://github.com/apache/dubbo-go/pull/1020


   


----------------------------------------------------------------
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.

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



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


[GitHub] [dubbo-go] zouyx commented on pull request #1020: Ftr: Add an "api way" to set general configure

Posted by GitBox <gi...@apache.org>.
zouyx commented on pull request #1020:
URL: https://github.com/apache/dubbo-go/pull/1020#issuecomment-774818950


   > This pull request may correspond to the [dubbo java's api configuration](https://dubbo.apache.org/docs/v2.7/user/configuration/api/). I think this is a nice configuration feature for people who start to use dubbo-go. @AlexStocks @zouyx
   
   I will agree,if not web API .


----------------------------------------------------------------
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.

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



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


[GitHub] [dubbo-go] AlexStocks commented on pull request #1020: Ftr: Add an "api way" to set general configure

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on pull request #1020:
URL: https://github.com/apache/dubbo-go/pull/1020#issuecomment-775787000


   very good pr. however, u should add comment for every func.


----------------------------------------------------------------
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.

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



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


[GitHub] [dubbo-go] gaoxinge commented on pull request #1020: Ftr: Add an "api way" to set general configure

Posted by GitBox <gi...@apache.org>.
gaoxinge commented on pull request #1020:
URL: https://github.com/apache/dubbo-go/pull/1020#issuecomment-773845878


   This pull request may correspond to the [dubbo java's api configuration](https://dubbo.apache.org/docs/v2.7/user/configuration/api/). I think this is a nice configuration feature for people who start to use dubbo-go.  @AlexStocks @zouyx 


----------------------------------------------------------------
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.

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



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


[GitHub] [dubbo-go] gaoxinge commented on a change in pull request #1020: Ftr/configAPI: Add an "api way" to set general configue.

Posted by GitBox <gi...@apache.org>.
gaoxinge commented on a change in pull request #1020:
URL: https://github.com/apache/dubbo-go/pull/1020#discussion_r564539145



##########
File path: config/config_api.go
##########
@@ -0,0 +1,473 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package config
+
+import (
+	"context"
+	"time"
+)
+
+//////////////////////////////////// default registry config
+const (
+	defaultZKAddr          = "127.0.0.1:2181"
+	defaultConsulAddr      = "127.0.0.1:8500"
+	defaultNacosAddr       = "127.0.0.1:8848"
+	defaultRegistryTimeout = "3s"
+)
+
+func NewDefaultRegistryConfig(protocol string) *RegistryConfig {
+	switch protocol {
+	case "zookeeper":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultZKAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	case "consul":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultConsulAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	case "nacos":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultNacosAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	default:
+		return &RegistryConfig{
+			Protocol: protocol,
+		}
+	}
+}
+
+///////////////////////////////////// registry config api
+type RegistryConfigOpt func(config *RegistryConfig) *RegistryConfig
+
+func NewRegistryConfig(opts ...RegistryConfigOpt) *RegistryConfig {
+	newRegistryConfig := NewDefaultRegistryConfig("none")
+	for _, v := range opts {
+		newRegistryConfig = v(newRegistryConfig)
+	}
+	return newRegistryConfig
+}
+
+func WithRegistryProtocol(regProtocol string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Protocol = regProtocol
+		return config
+	}
+}
+
+func WithRegistryAddress(addr string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Address = addr
+		return config
+	}
+}
+
+func WithRegistryTimeOut(timeout string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.TimeoutStr = timeout
+		return config
+	}
+}
+
+func WithRegistryGroup(group string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Group = group
+		return config
+	}
+}
+
+func WithRegistryTTL(ttl string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.TTL = ttl
+		return config
+	}
+}
+
+func WithRegistryUserName(userName string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Username = userName
+		return config
+	}
+}
+
+func WithRegistryPassword(psw string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Password = psw
+		return config
+	}
+}
+
+func WithRegistrySimplified(simplified bool) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Simplified = simplified
+		return config
+	}
+}
+
+func WithRegistryPreferred(preferred bool) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Preferred = preferred
+		return config
+	}
+}
+
+func WithRegistryWeight(weight int64) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Weight = weight
+		return config
+	}
+}
+
+func WithRegistryParams(params map[string]string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Params = params
+		return config
+	}
+}
+
+///////////////////////////////////// consumer config api
+type ConsumerConfigOpt func(config *ConsumerConfig) *ConsumerConfig
+
+func NewDefaultConsumerConfig() *ConsumerConfig {
+	check := true
+	newConsumerConfig := &ConsumerConfig{
+		BaseConfig:     BaseConfig{},
+		Registries:     make(map[string]*RegistryConfig, 8),
+		References:     make(map[string]*ReferenceConfig, 8),
+		ConnectTimeout: 3 * time.Second,
+		RequestTimeout: 3 * time.Second,
+		Check:          &check,
+	}
+	return newConsumerConfig
+}
+
+func NewConsumerConfig(opts ...ConsumerConfigOpt) *ConsumerConfig {
+	newConfig := NewDefaultConsumerConfig()
+	for _, v := range opts {
+		v(newConfig)
+	}
+	return newConfig
+}
+func WithConsumerAppConfig(appConfig *ApplicationConfig) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.ApplicationConfig = appConfig
+		return config
+	}
+}
+
+func WithConsumerRegistryConfig(registryKey string, regConfig *RegistryConfig) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.Registries[registryKey] = regConfig
+		return config
+	}
+}
+
+func WithConsumerReferenceConfig(referenceKey string, refConfig *ReferenceConfig) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.References[referenceKey] = refConfig
+		return config
+	}
+}
+
+func WithConsumerConnTimeout(timeout time.Duration) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.ConnectTimeout = timeout
+		return config
+	}
+}
+
+func WithConsumerRequestTimeout(timeout time.Duration) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.RequestTimeout = timeout
+		return config
+	}
+}
+
+func WithConsumerConfigCenterConfig(configCenterConfig *ConfigCenterConfig) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.ConfigCenterConfig = configCenterConfig
+		return config
+	}
+}
+
+func WithConsumerConfigCheck(check bool) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		*config.Check = check
+		return config
+	}
+}
+
+//////////////////////////////////// reference config api
+type ReferenceConfigOpt func(config *ReferenceConfig) *ReferenceConfig
+
+func NewDefaultReferenceConfig() *ReferenceConfig {
+	newReferenceConfig := NewReferenceConfig("", context.Background())
+	newReferenceConfig.Methods = make([]*MethodConfig, 0, 8)
+	newReferenceConfig.Params = make(map[string]string, 8)
+	return newReferenceConfig
+}
+
+func NewReferenceConfigByAPI(opts ...ReferenceConfigOpt) *ReferenceConfig {
+	newreferenceConfig := NewDefaultReferenceConfig()
+	for _, v := range opts {
+		v(newreferenceConfig)
+	}
+	return newreferenceConfig
+}
+
+func WithReferenceRegistry(registry string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.Registry = registry
+		return config
+	}
+}
+func WithReferenceProtocol(protocol string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.Protocol = protocol
+		return config
+	}
+}
+func WithReferenceInterface(interfaceName string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.InterfaceName = interfaceName
+		return config
+	}
+}
+func WithReferenceCluster(cluster string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.Cluster = cluster
+		return config
+	}
+}
+func WithReferenceMethod(methodName, retries, lb string) ReferenceConfigOpt {

Review comment:
       Add blank between functions.

##########
File path: config/config_api.go
##########
@@ -0,0 +1,473 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package config
+
+import (
+	"context"
+	"time"
+)
+
+//////////////////////////////////// default registry config
+const (
+	defaultZKAddr          = "127.0.0.1:2181"
+	defaultConsulAddr      = "127.0.0.1:8500"
+	defaultNacosAddr       = "127.0.0.1:8848"
+	defaultRegistryTimeout = "3s"
+)
+
+func NewDefaultRegistryConfig(protocol string) *RegistryConfig {
+	switch protocol {
+	case "zookeeper":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultZKAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	case "consul":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultConsulAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	case "nacos":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultNacosAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	default:
+		return &RegistryConfig{
+			Protocol: protocol,
+		}
+	}
+}
+
+///////////////////////////////////// registry config api
+type RegistryConfigOpt func(config *RegistryConfig) *RegistryConfig
+
+func NewRegistryConfig(opts ...RegistryConfigOpt) *RegistryConfig {
+	newRegistryConfig := NewDefaultRegistryConfig("none")

Review comment:
       Use empty string "" instead of "none".




----------------------------------------------------------------
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.

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



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


[GitHub] [dubbo-go] AlexStocks commented on pull request #1020: Ftr: Add an "api way" to set general configure

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on pull request #1020:
URL: https://github.com/apache/dubbo-go/pull/1020#issuecomment-770714826


   pls change the target branch to 1.5


----------------------------------------------------------------
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.

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



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


[GitHub] [dubbo-go] LaurenceLiZhixin commented on a change in pull request #1020: Ftr/configAPI: Add an "api way" to set general configue.

Posted by GitBox <gi...@apache.org>.
LaurenceLiZhixin commented on a change in pull request #1020:
URL: https://github.com/apache/dubbo-go/pull/1020#discussion_r565157052



##########
File path: config/config_api.go
##########
@@ -0,0 +1,473 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package config
+
+import (
+	"context"
+	"time"
+)
+
+//////////////////////////////////// default registry config
+const (
+	defaultZKAddr          = "127.0.0.1:2181"
+	defaultConsulAddr      = "127.0.0.1:8500"
+	defaultNacosAddr       = "127.0.0.1:8848"
+	defaultRegistryTimeout = "3s"
+)
+
+func NewDefaultRegistryConfig(protocol string) *RegistryConfig {
+	switch protocol {
+	case "zookeeper":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultZKAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	case "consul":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultConsulAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	case "nacos":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultNacosAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	default:
+		return &RegistryConfig{
+			Protocol: protocol,
+		}
+	}
+}
+
+///////////////////////////////////// registry config api
+type RegistryConfigOpt func(config *RegistryConfig) *RegistryConfig
+
+func NewRegistryConfig(opts ...RegistryConfigOpt) *RegistryConfig {
+	newRegistryConfig := NewDefaultRegistryConfig("none")
+	for _, v := range opts {
+		newRegistryConfig = v(newRegistryConfig)
+	}
+	return newRegistryConfig
+}
+
+func WithRegistryProtocol(regProtocol string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Protocol = regProtocol
+		return config
+	}
+}
+
+func WithRegistryAddress(addr string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Address = addr
+		return config
+	}
+}
+
+func WithRegistryTimeOut(timeout string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.TimeoutStr = timeout
+		return config
+	}
+}
+
+func WithRegistryGroup(group string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Group = group
+		return config
+	}
+}
+
+func WithRegistryTTL(ttl string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.TTL = ttl
+		return config
+	}
+}
+
+func WithRegistryUserName(userName string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Username = userName
+		return config
+	}
+}
+
+func WithRegistryPassword(psw string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Password = psw
+		return config
+	}
+}
+
+func WithRegistrySimplified(simplified bool) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Simplified = simplified
+		return config
+	}
+}
+
+func WithRegistryPreferred(preferred bool) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Preferred = preferred
+		return config
+	}
+}
+
+func WithRegistryWeight(weight int64) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Weight = weight
+		return config
+	}
+}
+
+func WithRegistryParams(params map[string]string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Params = params
+		return config
+	}
+}
+
+///////////////////////////////////// consumer config api
+type ConsumerConfigOpt func(config *ConsumerConfig) *ConsumerConfig
+
+func NewDefaultConsumerConfig() *ConsumerConfig {
+	check := true
+	newConsumerConfig := &ConsumerConfig{
+		BaseConfig:     BaseConfig{},
+		Registries:     make(map[string]*RegistryConfig, 8),
+		References:     make(map[string]*ReferenceConfig, 8),
+		ConnectTimeout: 3 * time.Second,
+		RequestTimeout: 3 * time.Second,
+		Check:          &check,
+	}
+	return newConsumerConfig
+}
+
+func NewConsumerConfig(opts ...ConsumerConfigOpt) *ConsumerConfig {
+	newConfig := NewDefaultConsumerConfig()
+	for _, v := range opts {
+		v(newConfig)
+	}
+	return newConfig
+}
+func WithConsumerAppConfig(appConfig *ApplicationConfig) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.ApplicationConfig = appConfig
+		return config
+	}
+}
+
+func WithConsumerRegistryConfig(registryKey string, regConfig *RegistryConfig) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.Registries[registryKey] = regConfig
+		return config
+	}
+}
+
+func WithConsumerReferenceConfig(referenceKey string, refConfig *ReferenceConfig) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.References[referenceKey] = refConfig
+		return config
+	}
+}
+
+func WithConsumerConnTimeout(timeout time.Duration) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.ConnectTimeout = timeout
+		return config
+	}
+}
+
+func WithConsumerRequestTimeout(timeout time.Duration) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.RequestTimeout = timeout
+		return config
+	}
+}
+
+func WithConsumerConfigCenterConfig(configCenterConfig *ConfigCenterConfig) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.ConfigCenterConfig = configCenterConfig
+		return config
+	}
+}
+
+func WithConsumerConfigCheck(check bool) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		*config.Check = check
+		return config
+	}
+}
+
+//////////////////////////////////// reference config api
+type ReferenceConfigOpt func(config *ReferenceConfig) *ReferenceConfig
+
+func NewDefaultReferenceConfig() *ReferenceConfig {
+	newReferenceConfig := NewReferenceConfig("", context.Background())
+	newReferenceConfig.Methods = make([]*MethodConfig, 0, 8)
+	newReferenceConfig.Params = make(map[string]string, 8)
+	return newReferenceConfig
+}
+
+func NewReferenceConfigByAPI(opts ...ReferenceConfigOpt) *ReferenceConfig {
+	newreferenceConfig := NewDefaultReferenceConfig()
+	for _, v := range opts {
+		v(newreferenceConfig)
+	}
+	return newreferenceConfig
+}
+
+func WithReferenceRegistry(registry string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.Registry = registry
+		return config
+	}
+}
+func WithReferenceProtocol(protocol string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.Protocol = protocol
+		return config
+	}
+}
+func WithReferenceInterface(interfaceName string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.InterfaceName = interfaceName
+		return config
+	}
+}
+func WithReferenceCluster(cluster string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.Cluster = cluster
+		return config
+	}
+}
+func WithReferenceMethod(methodName, retries, lb string) ReferenceConfigOpt {

Review comment:
       fixed!

##########
File path: config/config_api.go
##########
@@ -0,0 +1,473 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package config
+
+import (
+	"context"
+	"time"
+)
+
+//////////////////////////////////// default registry config
+const (
+	defaultZKAddr          = "127.0.0.1:2181"
+	defaultConsulAddr      = "127.0.0.1:8500"
+	defaultNacosAddr       = "127.0.0.1:8848"
+	defaultRegistryTimeout = "3s"
+)
+
+func NewDefaultRegistryConfig(protocol string) *RegistryConfig {
+	switch protocol {
+	case "zookeeper":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultZKAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	case "consul":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultConsulAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	case "nacos":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultNacosAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	default:
+		return &RegistryConfig{
+			Protocol: protocol,
+		}
+	}
+}
+
+///////////////////////////////////// registry config api
+type RegistryConfigOpt func(config *RegistryConfig) *RegistryConfig
+
+func NewRegistryConfig(opts ...RegistryConfigOpt) *RegistryConfig {
+	newRegistryConfig := NewDefaultRegistryConfig("none")

Review comment:
       fixed!




----------------------------------------------------------------
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.

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



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


[GitHub] [dubbo-go] codecov-io commented on pull request #1020: Ftr/configAPI: Add an "api way" to set general configue.

Posted by GitBox <gi...@apache.org>.
codecov-io commented on pull request #1020:
URL: https://github.com/apache/dubbo-go/pull/1020#issuecomment-767489595


   # [Codecov](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=h1) Report
   > Merging [#1020](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=desc) (042a53f) into [develop](https://codecov.io/gh/apache/dubbo-go/commit/17c4a9e4e65ad9822a7262f5e39949f818e9bed1?el=desc) (17c4a9e) will **increase** coverage by `0.33%`.
   > The diff coverage is `74.25%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/dubbo-go/pull/1020/graphs/tree.svg?width=650&height=150&src=pr&token=dcPE6RyFAL)](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=tree)
   
   ```diff
   @@             Coverage Diff             @@
   ##           develop    #1020      +/-   ##
   ===========================================
   + Coverage    59.45%   59.79%   +0.33%     
   ===========================================
     Files          261      262       +1     
     Lines        12950    13152     +202     
   ===========================================
   + Hits          7700     7864     +164     
   - Misses        4276     4314      +38     
     Partials       974      974              
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [config/config\_api.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-Y29uZmlnL2NvbmZpZ19hcGkuZ28=) | `74.25% <74.25%> (ø)` | |
   | [remoting/kubernetes/registry\_controller.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-cmVtb3Rpbmcva3ViZXJuZXRlcy9yZWdpc3RyeV9jb250cm9sbGVyLmdv) | `46.12% <0.00%> (-5.31%)` | :arrow_down: |
   | [cluster/cluster\_impl/failback\_cluster\_invoker.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-Y2x1c3Rlci9jbHVzdGVyX2ltcGwvZmFpbGJhY2tfY2x1c3Rlcl9pbnZva2VyLmdv) | `73.49% <0.00%> (-2.41%)` | :arrow_down: |
   | [remoting/kubernetes/watch.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-cmVtb3Rpbmcva3ViZXJuZXRlcy93YXRjaC5nbw==) | `76.92% <0.00%> (ø)` | |
   | [remoting/kubernetes/listener.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-cmVtb3Rpbmcva3ViZXJuZXRlcy9saXN0ZW5lci5nbw==) | `50.52% <0.00%> (ø)` | |
   | [config/reference\_config.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-Y29uZmlnL3JlZmVyZW5jZV9jb25maWcuZ28=) | `79.80% <0.00%> (+0.96%)` | :arrow_up: |
   | [remoting/kubernetes/client.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-cmVtb3Rpbmcva3ViZXJuZXRlcy9jbGllbnQuZ28=) | `75.00% <0.00%> (+2.94%)` | :arrow_up: |
   | [config/service\_config.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-Y29uZmlnL3NlcnZpY2VfY29uZmlnLmdv) | `57.51% <0.00%> (+3.92%)` | :arrow_up: |
   | [...tocol/rest/server/server\_impl/go\_restful\_server.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-cHJvdG9jb2wvcmVzdC9zZXJ2ZXIvc2VydmVyX2ltcGwvZ29fcmVzdGZ1bF9zZXJ2ZXIuZ28=) | `48.78% <0.00%> (+4.87%)` | :arrow_up: |
   | ... and [2 more](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=footer). Last update [17c4a9e...042a53f](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
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.

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



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


[GitHub] [dubbo-go] codecov-io edited a comment on pull request #1020: Ftr/configAPI: Add an "api way" to set general configue.

Posted by GitBox <gi...@apache.org>.
codecov-io edited a comment on pull request #1020:
URL: https://github.com/apache/dubbo-go/pull/1020#issuecomment-767489595


   # [Codecov](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=h1) Report
   > Merging [#1020](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=desc) (8354e91) into [develop](https://codecov.io/gh/apache/dubbo-go/commit/c8fb3e934a6c3d15a0792a1396d0c122272f772c?el=desc) (c8fb3e9) will **increase** coverage by `0.20%`.
   > The diff coverage is `68.84%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/dubbo-go/pull/1020/graphs/tree.svg?width=650&height=150&src=pr&token=dcPE6RyFAL)](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=tree)
   
   ```diff
   @@             Coverage Diff             @@
   ##           develop    #1020      +/-   ##
   ===========================================
   + Coverage    59.54%   59.74%   +0.20%     
   ===========================================
     Files          261      262       +1     
     Lines        12957    13152     +195     
   ===========================================
   + Hits          7715     7858     +143     
   - Misses        4266     4316      +50     
   - Partials       976      978       +2     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=tree) | Coverage Δ | |
   |---|---|---|
   | [common/extension/metadata\_service.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-Y29tbW9uL2V4dGVuc2lvbi9tZXRhZGF0YV9zZXJ2aWNlLmdv) | `0.00% <0.00%> (ø)` | |
   | [filter/filter\_impl/sentinel\_filter.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-ZmlsdGVyL2ZpbHRlcl9pbXBsL3NlbnRpbmVsX2ZpbHRlci5nbw==) | `63.04% <ø> (ø)` | |
   | [metadata/service/remote/service.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-bWV0YWRhdGEvc2VydmljZS9yZW1vdGUvc2VydmljZS5nbw==) | `32.95% <0.00%> (ø)` | |
   | [...try/servicediscovery/service\_discovery\_registry.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-cmVnaXN0cnkvc2VydmljZWRpc2NvdmVyeS9zZXJ2aWNlX2Rpc2NvdmVyeV9yZWdpc3RyeS5nbw==) | `11.56% <ø> (-0.21%)` | :arrow_down: |
   | [config\_center/file/impl.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-Y29uZmlnX2NlbnRlci9maWxlL2ltcGwuZ28=) | `50.42% <42.85%> (+0.02%)` | :arrow_up: |
   | [registry/nacos/registry.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-cmVnaXN0cnkvbmFjb3MvcmVnaXN0cnkuZ28=) | `50.36% <57.14%> (-0.77%)` | :arrow_down: |
   | [config/config\_api.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-Y29uZmlnL2NvbmZpZ19hcGkuZ28=) | `74.25% <74.25%> (ø)` | |
   | [registry/etcdv3/registry.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-cmVnaXN0cnkvZXRjZHYzL3JlZ2lzdHJ5Lmdv) | `64.15% <75.00%> (-0.77%)` | :arrow_down: |
   | [...rotocol/protocolwrapper/protocol\_filter\_wrapper.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-cHJvdG9jb2wvcHJvdG9jb2x3cmFwcGVyL3Byb3RvY29sX2ZpbHRlcl93cmFwcGVyLmdv) | `50.00% <100.00%> (ø)` | |
   | [registry/etcdv3/listener.go](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree#diff-cmVnaXN0cnkvZXRjZHYzL2xpc3RlbmVyLmdv) | `67.50% <100.00%> (+1.71%)` | :arrow_up: |
   | ... and [16 more](https://codecov.io/gh/apache/dubbo-go/pull/1020/diff?src=pr&el=tree-more) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=continue).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=footer). Last update [4a721a2...8354e91](https://codecov.io/gh/apache/dubbo-go/pull/1020?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
   


----------------------------------------------------------------
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.

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



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


[GitHub] [dubbo-go] AlexStocks commented on a change in pull request #1020: Ftr: Add an "api way" to set general configure

Posted by GitBox <gi...@apache.org>.
AlexStocks commented on a change in pull request #1020:
URL: https://github.com/apache/dubbo-go/pull/1020#discussion_r565219578



##########
File path: config/config_api.go
##########
@@ -0,0 +1,480 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package config
+
+import (
+	"context"
+	"time"
+)
+
+//////////////////////////////////// default registry config
+const (
+	defaultZKAddr          = "127.0.0.1:2181"
+	defaultConsulAddr      = "127.0.0.1:8500"
+	defaultNacosAddr       = "127.0.0.1:8848"
+	defaultRegistryTimeout = "3s"
+)
+
+func NewDefaultRegistryConfig(protocol string) *RegistryConfig {
+	switch protocol {
+	case "zookeeper":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultZKAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	case "consul":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultConsulAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	case "nacos":
+		return &RegistryConfig{
+			Protocol:   protocol,
+			Address:    defaultNacosAddr,
+			TimeoutStr: defaultRegistryTimeout,
+		}
+	default:
+		return &RegistryConfig{
+			Protocol: protocol,
+		}
+	}
+}
+
+///////////////////////////////////// registry config api
+type RegistryConfigOpt func(config *RegistryConfig) *RegistryConfig
+
+func NewRegistryConfig(opts ...RegistryConfigOpt) *RegistryConfig {
+	newRegistryConfig := NewDefaultRegistryConfig("")
+	for _, v := range opts {
+		newRegistryConfig = v(newRegistryConfig)
+	}
+	return newRegistryConfig
+}
+
+func WithRegistryProtocol(regProtocol string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Protocol = regProtocol
+		return config
+	}
+}
+
+func WithRegistryAddress(addr string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Address = addr
+		return config
+	}
+}
+
+func WithRegistryTimeOut(timeout string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.TimeoutStr = timeout
+		return config
+	}
+}
+
+func WithRegistryGroup(group string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Group = group
+		return config
+	}
+}
+
+func WithRegistryTTL(ttl string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.TTL = ttl
+		return config
+	}
+}
+
+func WithRegistryUserName(userName string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Username = userName
+		return config
+	}
+}
+
+func WithRegistryPassword(psw string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Password = psw
+		return config
+	}
+}
+
+func WithRegistrySimplified(simplified bool) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Simplified = simplified
+		return config
+	}
+}
+
+func WithRegistryPreferred(preferred bool) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Preferred = preferred
+		return config
+	}
+}
+
+func WithRegistryWeight(weight int64) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Weight = weight
+		return config
+	}
+}
+
+func WithRegistryParams(params map[string]string) RegistryConfigOpt {
+	return func(config *RegistryConfig) *RegistryConfig {
+		config.Params = params
+		return config
+	}
+}
+
+///////////////////////////////////// consumer config api
+type ConsumerConfigOpt func(config *ConsumerConfig) *ConsumerConfig
+
+func NewDefaultConsumerConfig() *ConsumerConfig {
+	check := true
+	newConsumerConfig := &ConsumerConfig{
+		BaseConfig:     BaseConfig{},
+		Registries:     make(map[string]*RegistryConfig, 8),
+		References:     make(map[string]*ReferenceConfig, 8),
+		ConnectTimeout: 3 * time.Second,
+		RequestTimeout: 3 * time.Second,
+		Check:          &check,
+	}
+	return newConsumerConfig
+}
+
+func NewConsumerConfig(opts ...ConsumerConfigOpt) *ConsumerConfig {
+	newConfig := NewDefaultConsumerConfig()
+	for _, v := range opts {
+		v(newConfig)
+	}
+	return newConfig
+}
+
+func WithConsumerAppConfig(appConfig *ApplicationConfig) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.ApplicationConfig = appConfig
+		return config
+	}
+}
+
+func WithConsumerRegistryConfig(registryKey string, regConfig *RegistryConfig) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.Registries[registryKey] = regConfig
+		return config
+	}
+}
+
+func WithConsumerReferenceConfig(referenceKey string, refConfig *ReferenceConfig) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.References[referenceKey] = refConfig
+		return config
+	}
+}
+
+func WithConsumerConnTimeout(timeout time.Duration) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.ConnectTimeout = timeout
+		return config
+	}
+}
+
+func WithConsumerRequestTimeout(timeout time.Duration) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.RequestTimeout = timeout
+		return config
+	}
+}
+
+func WithConsumerConfigCenterConfig(configCenterConfig *ConfigCenterConfig) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		config.ConfigCenterConfig = configCenterConfig
+		return config
+	}
+}
+
+func WithConsumerConfigCheck(check bool) ConsumerConfigOpt {
+	return func(config *ConsumerConfig) *ConsumerConfig {
+		*config.Check = check
+		return config
+	}
+}
+
+//////////////////////////////////// reference config api
+type ReferenceConfigOpt func(config *ReferenceConfig) *ReferenceConfig
+
+func NewDefaultReferenceConfig() *ReferenceConfig {
+	newReferenceConfig := NewReferenceConfig("", context.Background())
+	newReferenceConfig.Methods = make([]*MethodConfig, 0, 8)
+	newReferenceConfig.Params = make(map[string]string, 8)
+	return newReferenceConfig
+}
+
+func NewReferenceConfigByAPI(opts ...ReferenceConfigOpt) *ReferenceConfig {
+	newreferenceConfig := NewDefaultReferenceConfig()
+	for _, v := range opts {
+		v(newreferenceConfig)
+	}
+	return newreferenceConfig
+}
+
+func WithReferenceRegistry(registry string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.Registry = registry
+		return config
+	}
+}
+
+func WithReferenceProtocol(protocol string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.Protocol = protocol
+		return config
+	}
+}
+
+func WithReferenceInterface(interfaceName string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.InterfaceName = interfaceName
+		return config
+	}
+}
+
+func WithReferenceCluster(cluster string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.Cluster = cluster
+		return config
+	}
+}
+
+func WithReferenceMethod(methodName, retries, lb string) ReferenceConfigOpt {
+	return func(config *ReferenceConfig) *ReferenceConfig {
+		config.Methods = append(config.Methods, &MethodConfig{
+			Name:        methodName,
+			Retries:     retries,
+			LoadBalance: lb,
+		})
+		return config
+	}
+}
+
+///////////////////////////////////// provider config api
+type ProviderConfigOpt func(config *ProviderConfig) *ProviderConfig
+
+func NewDefaultProviderConfig() *ProviderConfig {
+	newConsumerConfig := &ProviderConfig{
+		BaseConfig: BaseConfig{
+			ApplicationConfig: &ApplicationConfig{
+				Name:         "dubbo",
+				Module:       "module",
+				Organization: "dubbo_org",
+				Owner:        "dubbo",
+			},
+		},
+		Services:   make(map[string]*ServiceConfig),
+		Registries: make(map[string]*RegistryConfig, 8),
+		Protocols:  make(map[string]*ProtocolConfig, 8),
+	}
+	return newConsumerConfig
+}
+
+func NewProviderConfig(opts ...ProviderConfigOpt) *ProviderConfig {
+	newConfig := NewDefaultProviderConfig()
+	for _, v := range opts {
+		v(newConfig)
+	}
+	return newConfig
+}
+
+func WithPrividerRegistryConfig(regConfig *RegistryConfig) ProviderConfigOpt {
+	return func(config *ProviderConfig) *ProviderConfig {
+		config.Registries[regConfig.Protocol] = regConfig
+		return config
+	}
+}
+
+func WithProviderAppConfig(appConfig *ApplicationConfig) ProviderConfigOpt {
+	return func(config *ProviderConfig) *ProviderConfig {
+		config.ApplicationConfig = appConfig
+		return config
+	}
+}
+
+func WithProviderServices(serviceName string, serviceConfig *ServiceConfig) ProviderConfigOpt {
+	return func(config *ProviderConfig) *ProviderConfig {
+		config.Services[serviceName] = serviceConfig
+		return config
+	}
+}
+
+func WithProviderProtocol(protocolKey, protocol, port string) ProviderConfigOpt {
+	return func(config *ProviderConfig) *ProviderConfig {
+		config.Protocols[protocolKey] = &ProtocolConfig{
+			Name: protocol,
+			Port: port,
+		}
+		return config
+	}
+}
+
+func WithProviderRegistry(registryKey string, registryConfig *RegistryConfig) ProviderConfigOpt {
+	return func(config *ProviderConfig) *ProviderConfig {
+		config.Registries[registryKey] = registryConfig
+		return config
+	}
+}
+
+/////////////////////////////////////// service config api
+type ServiceConfigOpt func(config *ServiceConfig) *ServiceConfig
+
+func NewDefaultServiceConfig() *ServiceConfig {
+	newServiceConfig := NewServiceConfig("", context.Background())
+	newServiceConfig.Params = make(map[string]string)
+	newServiceConfig.Methods = make([]*MethodConfig, 0, 8)
+	return newServiceConfig
+}
+
+// NewServiceConfigByAPI is named as api, because there is NewServiceConfig func already declared
+func NewServiceConfigByAPI(opts ...ServiceConfigOpt) *ServiceConfig {
+	defaultServiceConfig := NewDefaultServiceConfig()
+	for _, v := range opts {
+		v(defaultServiceConfig)
+	}
+	return defaultServiceConfig
+}
+
+func WithServiceRegistry(registry string) ServiceConfigOpt {
+	return func(config *ServiceConfig) *ServiceConfig {
+		config.Registry = registry
+		return config
+	}
+}
+
+func WithServiceProtocol(protocol string) ServiceConfigOpt {
+	return func(config *ServiceConfig) *ServiceConfig {
+		config.Protocol = protocol
+		return config
+	}
+}
+
+func WithServiceInterface(interfaceName string) ServiceConfigOpt {
+	return func(config *ServiceConfig) *ServiceConfig {
+		config.InterfaceName = interfaceName
+		return config
+	}
+}
+
+func WithServiceLoadBalance(lb string) ServiceConfigOpt {
+	return func(config *ServiceConfig) *ServiceConfig {
+		config.Loadbalance = lb
+		return config
+	}
+}
+
+func WithServiceWarmUpTime(warmUp string) ServiceConfigOpt {
+	return func(config *ServiceConfig) *ServiceConfig {
+		config.Warmup = warmUp
+		return config
+	}
+}
+
+func WithServiceCluster(cluster string) ServiceConfigOpt {
+	return func(config *ServiceConfig) *ServiceConfig {
+		config.Cluster = cluster
+		return config
+	}
+}
+
+func WithServiceMethod(name, retries, lb string) ServiceConfigOpt {
+	return func(config *ServiceConfig) *ServiceConfig {
+		config.Methods = append(config.Methods, &MethodConfig{
+			Name:        name,
+			Retries:     retries,
+			LoadBalance: lb,
+		})
+		return config
+	}
+}
+
+///////////////////////////////////////// Application config api

Review comment:
       // enough




----------------------------------------------------------------
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.

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



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


[GitHub] [dubbo-go] gaoxinge commented on pull request #1020: Ftr: Add an "api way" to set general configure

Posted by GitBox <gi...@apache.org>.
gaoxinge commented on pull request #1020:
URL: https://github.com/apache/dubbo-go/pull/1020#issuecomment-773845878


   This pull request may correspond to the [dubbo java's api configuration](https://dubbo.apache.org/docs/v2.7/user/configuration/api/). I think this is a nice configuration feature for people who start to use dubbo-go.  @AlexStocks @zouyx 


----------------------------------------------------------------
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.

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



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