You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by li...@apache.org on 2023/10/26 07:46:06 UTC
[dubbo-go] branch feature-triple updated: Fix #2446, move XxxOption definition in global package to separate packages (#2447)
This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch feature-triple
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git
The following commit(s) were added to refs/heads/feature-triple by this push:
new 9d62f726a Fix #2446, move XxxOption definition in global package to separate packages (#2447)
9d62f726a is described below
commit 9d62f726adbadfb63f0cc7a8cfcbd39b7618864f
Author: Ken Liu <ke...@gmail.com>
AuthorDate: Thu Oct 26 15:46:00 2023 +0800
Fix #2446, move XxxOption definition in global package to separate packages (#2447)
---
config/protocol_config.go | 4 +-
config_center/dynamic_configuration.go | 27 ------
config_center/file/impl.go | 21 ++---
config_center/nacos/impl.go | 7 +-
config_center/options.go | 159 +++++++++++++++++++++++++++++++++
config_center/zookeeper/impl.go | 9 +-
global/config_center_config.go | 79 ----------------
global/custom_config.go | 6 ++
global/metadata_report_config.go | 44 ---------
global/metric_config.go | 123 +++----------------------
global/protocol_config.go | 38 --------
global/registry_config.go | 98 --------------------
global/tls_config.go | 5 ++
global/tracing_config.go | 26 ------
go.mod | 1 +
{protocol => logger}/options.go | 76 ++++++----------
metadata/options.go | 104 +++++++++++++++++++++
metrics/options.go | 125 ++++++++++++++++++++++++++
options.go | 111 ++++++++++-------------
{protocol => otel/trace}/options.go | 66 +++++---------
protocol/options.go | 17 ++--
registry/options.go | 10 +--
22 files changed, 529 insertions(+), 627 deletions(-)
diff --git a/config/protocol_config.go b/config/protocol_config.go
index 39cb95f1d..4443aa5ea 100644
--- a/config/protocol_config.go
+++ b/config/protocol_config.go
@@ -27,9 +27,9 @@ import (
// ProtocolConfig is protocol configuration
type ProtocolConfig struct {
- Name string `default:"dubbo" validate:"required" yaml:"name" json:"name,omitempty" property:"name"`
+ Name string `default:"tri" validate:"required" yaml:"name" json:"name,omitempty" property:"name"`
Ip string `yaml:"ip" json:"ip,omitempty" property:"ip"`
- Port string `default:"20000" yaml:"port" json:"port,omitempty" property:"port"`
+ Port string `default:"50051" yaml:"port" json:"port,omitempty" property:"port"`
Params interface{} `yaml:"params" json:"params,omitempty" property:"params"`
// MaxServerSendMsgSize max size of server send message, 1mb=1000kb=1000000b 1mib=1024kb=1048576b.
diff --git a/config_center/dynamic_configuration.go b/config_center/dynamic_configuration.go
index 79e93f27b..05d48acf1 100644
--- a/config_center/dynamic_configuration.go
+++ b/config_center/dynamic_configuration.go
@@ -17,10 +17,6 @@
package config_center
-import (
- "time"
-)
-
import (
gxset "github.com/dubbogo/gost/container/set"
)
@@ -62,29 +58,6 @@ type DynamicConfiguration interface {
GetConfigKeysByGroup(group string) (*gxset.HashSet, error)
}
-// Options ...
-type Options struct {
- Group string
- Timeout time.Duration
-}
-
-// Option ...
-type Option func(*Options)
-
-// WithGroup assigns group to opt.Group
-func WithGroup(group string) Option {
- return func(opt *Options) {
- opt.Group = group
- }
-}
-
-// WithTimeout assigns time to opt.Timeout
-func WithTimeout(time time.Duration) Option {
- return func(opt *Options) {
- opt.Timeout = time
- }
-}
-
// GetRuleKey The format is '{interfaceName}:[version]:[group]'
func GetRuleKey(url *common.URL) string {
return url.ColonSeparatedKey()
diff --git a/config_center/file/impl.go b/config_center/file/impl.go
index 2261eba15..287ca1e10 100644
--- a/config_center/file/impl.go
+++ b/config_center/file/impl.go
@@ -103,35 +103,26 @@ func (fsdc *FileSystemDynamicConfiguration) SetParser(p parser.ConfigurationPars
// AddListener Add listener
func (fsdc *FileSystemDynamicConfiguration) AddListener(key string, listener config_center.ConfigurationListener,
opts ...config_center.Option) {
- tmpOpts := &config_center.Options{}
- for _, opt := range opts {
- opt(tmpOpts)
- }
+ tmpOpts := config_center.NewOptions(opts...)
- tmpPath := fsdc.GetPath(key, tmpOpts.Group)
+ tmpPath := fsdc.GetPath(key, tmpOpts.Center.Group)
fsdc.cacheListener.AddListener(tmpPath, listener)
}
// RemoveListener Remove listener
func (fsdc *FileSystemDynamicConfiguration) RemoveListener(key string, listener config_center.ConfigurationListener,
opts ...config_center.Option) {
- tmpOpts := &config_center.Options{}
- for _, opt := range opts {
- opt(tmpOpts)
- }
+ tmpOpts := config_center.NewOptions(opts...)
- tmpPath := fsdc.GetPath(key, tmpOpts.Group)
+ tmpPath := fsdc.GetPath(key, tmpOpts.Center.Group)
fsdc.cacheListener.RemoveListener(tmpPath, listener)
}
// GetProperties get properties file
func (fsdc *FileSystemDynamicConfiguration) GetProperties(key string, opts ...config_center.Option) (string, error) {
- tmpOpts := &config_center.Options{}
- for _, opt := range opts {
- opt(tmpOpts)
- }
+ tmpOpts := config_center.NewOptions(opts...)
- tmpPath := fsdc.GetPath(key, tmpOpts.Group)
+ tmpPath := fsdc.GetPath(key, tmpOpts.Center.Group)
file, err := ioutil.ReadFile(tmpPath)
if err != nil {
return "", perrors.WithStack(err)
diff --git a/config_center/nacos/impl.go b/config_center/nacos/impl.go
index 5b1c50fb8..a6b728f36 100644
--- a/config_center/nacos/impl.go
+++ b/config_center/nacos/impl.go
@@ -162,11 +162,8 @@ func (n *nacosDynamicConfiguration) GetConfigKeysByGroup(group string) (*gxset.H
// GetRule Get router rule
func (n *nacosDynamicConfiguration) GetRule(key string, opts ...config_center.Option) (string, error) {
- tmpOpts := &config_center.Options{}
- for _, opt := range opts {
- opt(tmpOpts)
- }
- resolvedGroup := n.resolvedGroup(tmpOpts.Group)
+ tmpOpts := config_center.NewOptions(opts...)
+ resolvedGroup := n.resolvedGroup(tmpOpts.Center.Group)
content, err := n.client.Client().GetConfig(vo.ConfigParam{
DataId: key,
Group: resolvedGroup,
diff --git a/config_center/options.go b/config_center/options.go
new file mode 100644
index 000000000..3fa9e1b38
--- /dev/null
+++ b/config_center/options.go
@@ -0,0 +1,159 @@
+/*
+ * 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_center
+
+import (
+ "strconv"
+ "strings"
+ "time"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/common/constant/file"
+ "dubbo.apache.org/dubbo-go/v3/global"
+)
+
+type Options struct {
+ Center *global.CenterConfig
+}
+
+func defaultOptions() *Options {
+ return &Options{Center: global.DefaultCenterConfig()}
+}
+
+func NewOptions(opts ...Option) *Options {
+ centerOptions := defaultOptions()
+ for _, opt := range opts {
+ opt(centerOptions)
+ }
+ return centerOptions
+}
+
+type Option func(*Options)
+
+func WithZookeeper() Option {
+ return func(opts *Options) {
+ opts.Center.Protocol = constant.ZookeeperKey
+ }
+}
+
+func WithNacos() Option {
+ return func(opts *Options) {
+ opts.Center.Protocol = constant.NacosKey
+ }
+}
+
+func WithAddress(address string) Option {
+ return func(opts *Options) {
+ if i := strings.Index(address, "://"); i > 0 {
+ opts.Center.Protocol = address[0:i]
+ }
+ opts.Center.Address = address
+ }
+}
+
+func WithDataID(id string) Option {
+ return func(opts *Options) {
+ opts.Center.DataId = id
+ }
+}
+
+func WithCluster(cluster string) Option {
+ return func(opts *Options) {
+ opts.Center.Cluster = cluster
+ }
+}
+
+func WithGroup(group string) Option {
+ return func(opts *Options) {
+ opts.Center.Group = group
+ }
+}
+
+func WithUsername(username string) Option {
+ return func(opts *Options) {
+ opts.Center.Username = username
+ }
+}
+
+func WithPassword(password string) Option {
+ return func(opts *Options) {
+ opts.Center.Password = password
+ }
+}
+
+func WithNamespace(namespace string) Option {
+ return func(opts *Options) {
+ opts.Center.Namespace = namespace
+ }
+}
+
+func WithAppID(id string) Option {
+ return func(opts *Options) {
+ opts.Center.AppID = id
+ }
+}
+
+func WithTimeout(timeout time.Duration) Option {
+ return func(opts *Options) {
+ opts.Center.Timeout = strconv.Itoa(int(timeout.Milliseconds()))
+ }
+}
+
+func WithParams(params map[string]string) Option {
+ return func(opts *Options) {
+ opts.Center.Params = params
+ }
+}
+
+func WithFile() Option {
+ return func(opts *Options) {
+ opts.Center.Protocol = constant.FileKey
+ }
+}
+
+func WithFileExtJson() Option {
+ return func(opts *Options) {
+ opts.Center.FileExtension = string(file.JSON)
+ }
+}
+
+func WithFileExtToml() Option {
+ return func(opts *Options) {
+ opts.Center.FileExtension = string(file.TOML)
+ }
+}
+
+func WithFileExtYaml() Option {
+ return func(opts *Options) {
+ opts.Center.FileExtension = string(file.YAML)
+ }
+}
+
+func WithFileExtYml() Option {
+ return func(opts *Options) {
+ opts.Center.FileExtension = string(file.YML)
+ }
+}
+
+func WithFileExtProperties() Option {
+ return func(opts *Options) {
+ opts.Center.FileExtension = string(file.PROPERTIES)
+ }
+}
diff --git a/config_center/zookeeper/impl.go b/config_center/zookeeper/impl.go
index b6c3e6be5..14b529ab6 100644
--- a/config_center/zookeeper/impl.go
+++ b/config_center/zookeeper/impl.go
@@ -123,16 +123,13 @@ func (c *zookeeperDynamicConfiguration) RemoveListener(key string, listener conf
}
func (c *zookeeperDynamicConfiguration) GetProperties(key string, opts ...config_center.Option) (string, error) {
- tmpOpts := &config_center.Options{}
- for _, opt := range opts {
- opt(tmpOpts)
- }
+ tmpOpts := config_center.NewOptions(opts...)
/**
* when group is not null, we are getting startup configs from Config Center, for example:
* group=dubbo, key=dubbo.properties
*/
- if len(tmpOpts.Group) != 0 {
- key = tmpOpts.Group + "/" + key
+ if len(tmpOpts.Center.Group) != 0 {
+ key = tmpOpts.Center.Group + "/" + key
} else {
key = c.GetURL().GetParam(constant.ConfigNamespaceKey, config_center.DefaultGroup) + "/" + key
}
diff --git a/global/config_center_config.go b/global/config_center_config.go
index d219b693a..f66c6b687 100644
--- a/global/config_center_config.go
+++ b/global/config_center_config.go
@@ -29,82 +29,3 @@ func DefaultCenterConfig() *CenterConfig {
Params: make(map[string]string),
}
}
-
-type CenterOption func(*CenterConfig)
-
-func WithCenter_Protocol(protocol string) CenterOption {
- return func(cfg *CenterConfig) {
- cfg.Protocol = protocol
- }
-}
-
-func WithCenter_Address(address string) CenterOption {
- return func(cfg *CenterConfig) {
- cfg.Address = address
- }
-}
-
-func WithCenter_DataID(id string) CenterOption {
- return func(cfg *CenterConfig) {
- cfg.DataId = id
- }
-}
-
-func WithCenter_Cluster(cluster string) CenterOption {
- return func(cfg *CenterConfig) {
- cfg.Cluster = cluster
- }
-}
-
-func WithCenter_Group(group string) CenterOption {
- return func(cfg *CenterConfig) {
- cfg.Group = group
- }
-}
-
-func WithCenter_Username(name string) CenterOption {
- return func(cfg *CenterConfig) {
- cfg.Username = name
- }
-}
-
-func WithCenter_Password(password string) CenterOption {
- return func(cfg *CenterConfig) {
- cfg.Password = password
- }
-}
-
-func WithCenter_Namespace(namespace string) CenterOption {
- return func(cfg *CenterConfig) {
- cfg.Namespace = namespace
- }
-}
-
-func WithCenter_AppID(id string) CenterOption {
- return func(cfg *CenterConfig) {
- cfg.AppID = id
- }
-}
-
-func WithCenter_Timeout(timeout string) CenterOption {
- return func(cfg *CenterConfig) {
- cfg.Timeout = timeout
- }
-}
-
-func WithCenter_Params(params map[string]string) CenterOption {
- return func(cfg *CenterConfig) {
- if cfg.Params == nil {
- cfg.Params = make(map[string]string)
- }
- for k, v := range params {
- cfg.Params[k] = v
- }
- }
-}
-
-func WithCenter_FileExtension(extension string) CenterOption {
- return func(cfg *CenterConfig) {
- cfg.FileExtension = extension
- }
-}
diff --git a/global/custom_config.go b/global/custom_config.go
index e35e4067a..3fcb8927f 100644
--- a/global/custom_config.go
+++ b/global/custom_config.go
@@ -17,6 +17,12 @@
package global
+// CustomConfig
+//
+// # Experimental
+//
+// Notice: This struct is EXPERIMENTAL and may be changed or removed in a
+// later release.
type CustomConfig struct {
ConfigMap map[string]interface{} `yaml:"config-map" json:"config-map,omitempty" property:"config-map"`
}
diff --git a/global/metadata_report_config.go b/global/metadata_report_config.go
index 65c97f6d1..718ea19f4 100644
--- a/global/metadata_report_config.go
+++ b/global/metadata_report_config.go
@@ -34,47 +34,3 @@ func DefaultMetadataReportConfig() *MetadataReportConfig {
// return a new config without setting any field means there is not any default value for initialization
return &MetadataReportConfig{}
}
-
-type MetadataReportOption func(*MetadataReportConfig)
-
-func WithMetadataReport_Protocol(protocol string) MetadataReportOption {
- return func(cfg *MetadataReportConfig) {
- cfg.Protocol = protocol
- }
-}
-
-func WithMetadataReport_Address(address string) MetadataReportOption {
- return func(cfg *MetadataReportConfig) {
- cfg.Address = address
- }
-}
-
-func WithMetadataReport_Username(username string) MetadataReportOption {
- return func(cfg *MetadataReportConfig) {
- cfg.Username = username
- }
-}
-
-func WithMetadataReport_Password(password string) MetadataReportOption {
- return func(cfg *MetadataReportConfig) {
- cfg.Password = password
- }
-}
-
-func WithMetadataReport_Timeout(timeout string) MetadataReportOption {
- return func(cfg *MetadataReportConfig) {
- cfg.Timeout = timeout
- }
-}
-
-func WithMetadataReport_Group(group string) MetadataReportOption {
- return func(cfg *MetadataReportConfig) {
- cfg.Group = group
- }
-}
-
-func WithMetadataReport_Namespace(namespace string) MetadataReportOption {
- return func(cfg *MetadataReportConfig) {
- cfg.Namespace = namespace
- }
-}
diff --git a/global/metric_config.go b/global/metric_config.go
index ce6124c34..eaeec7047 100644
--- a/global/metric_config.go
+++ b/global/metric_config.go
@@ -43,127 +43,24 @@ type Exporter struct {
}
type PushgatewayConfig struct {
- Enabled *bool `default:"false" yaml:"enabled" json:"enabled,omitempty" property:"enabled"`
- BaseUrl string `default:"" yaml:"base-url" json:"base-url,omitempty" property:"base-url"`
- Job string `default:"default_dubbo_job" yaml:"job" json:"job,omitempty" property:"job"`
- Username string `default:"" yaml:"username" json:"username,omitempty" property:"username"`
- Password string `default:"" yaml:"password" json:"password,omitempty" property:"password"`
- PushInterval int `default:"30" yaml:"push-interval" json:"push-interval,omitempty" property:"push-interval"`
+ Enabled *bool `default:"false" yaml:"enabled" json:"enabled,omitempty" property:"enabled"`
+ BaseUrl string `default:"" yaml:"base-url" json:"base-url,omitempty" property:"base-url"`
+ Job string `default:"default_dubbo_job" yaml:"job" json:"job,omitempty" property:"job"`
+ Username string `default:"" yaml:"username" json:"username,omitempty" property:"username"`
+ Password string `default:"" yaml:"password" json:"password,omitempty" property:"password"`
+ // seconds
+ PushInterval int `default:"30" yaml:"push-interval" json:"push-interval,omitempty" property:"push-interval"`
}
func DefaultMetricConfig() *MetricConfig {
// return a new config without setting any field means there is not any default value for initialization
- return &MetricConfig{}
+ return &MetricConfig{Prometheus: defaultPrometheusConfig(), Aggregation: defaultAggregateConfig()}
}
func defaultPrometheusConfig() *PrometheusConfig {
return &PrometheusConfig{Exporter: &Exporter{}, Pushgateway: &PushgatewayConfig{}}
}
-type MetricOption func(*MetricConfig)
-
-func WithMetric_AggregateEnabled() MetricOption {
- return func(cfg *MetricConfig) {
- if cfg.Aggregation == nil {
- cfg.Aggregation = &AggregateConfig{}
- }
- enabled := true
- cfg.Aggregation.Enabled = &enabled
- }
-}
-
-func WithMetric_AggregateBucketNum(num int) MetricOption {
- return func(cfg *MetricConfig) {
- if cfg.Aggregation == nil {
- cfg.Aggregation = &AggregateConfig{}
- }
- cfg.Aggregation.BucketNum = num
- }
-}
-
-func WithMetric_AggregateTimeWindowSeconds(seconds int) MetricOption {
- return func(cfg *MetricConfig) {
- if cfg.Aggregation == nil {
- cfg.Aggregation = &AggregateConfig{}
- }
- cfg.Aggregation.TimeWindowSeconds = seconds
- }
-}
-
-func WithMetric_PrometheusEnabled() MetricOption {
- return func(cfg *MetricConfig) {
- if cfg.Prometheus == nil {
- cfg.Prometheus.Exporter = &Exporter{}
- }
- enabled := true
- cfg.Prometheus.Exporter.Enabled = &enabled
- }
-}
-
-func WithMetric_PrometheusGatewayUrl(url string) MetricOption {
- return func(cfg *MetricConfig) {
- if cfg.Prometheus == nil {
- cfg.Prometheus = defaultPrometheusConfig()
- }
- cfg.Prometheus.Pushgateway.BaseUrl = url
- }
-}
-
-func WithMetric_PrometheusGatewayJob(job string) MetricOption {
- return func(cfg *MetricConfig) {
- if cfg.Prometheus == nil {
- cfg.Prometheus = defaultPrometheusConfig()
- }
- cfg.Prometheus.Pushgateway.Job = job
- }
-}
-
-func WithMetric_PrometheusGatewayUsername(username string) MetricOption {
- return func(cfg *MetricConfig) {
- if cfg.Prometheus == nil {
- cfg.Prometheus = defaultPrometheusConfig()
- }
- cfg.Prometheus.Pushgateway.Username = username
- }
-}
-
-func WithMetric_PrometheusGatewayPassword(password string) MetricOption {
- return func(cfg *MetricConfig) {
- if cfg.Prometheus == nil {
- cfg.Prometheus = defaultPrometheusConfig()
- }
- cfg.Prometheus.Pushgateway.Password = password
- }
-}
-func WithMetric_PrometheusGatewayInterval(interval int) MetricOption {
- return func(cfg *MetricConfig) {
- if cfg.Prometheus == nil {
- cfg.Prometheus = defaultPrometheusConfig()
- }
- cfg.Prometheus.Pushgateway.PushInterval = interval
- }
-}
-
-func WithMetric_Enable(enable bool) MetricOption {
- return func(cfg *MetricConfig) {
- cfg.Enable = &enable
- }
-}
-
-func WithMetric_Port(port string) MetricOption {
- return func(cfg *MetricConfig) {
- cfg.Port = port
- }
-}
-
-func WithMetric_Path(path string) MetricOption {
- return func(cfg *MetricConfig) {
- cfg.Path = path
- }
-}
-
-func WithMetric_Protocol(protocol string) MetricOption {
- return func(cfg *MetricConfig) {
- cfg.Protocol = protocol
- }
+func defaultAggregateConfig() *AggregateConfig {
+ return &AggregateConfig{}
}
diff --git a/global/protocol_config.go b/global/protocol_config.go
index 25f1ae2b7..ebfa3dd5e 100644
--- a/global/protocol_config.go
+++ b/global/protocol_config.go
@@ -34,41 +34,3 @@ type ProtocolConfig struct {
func DefaultProtocolConfig() *ProtocolConfig {
return &ProtocolConfig{}
}
-
-type ProtocolOption func(*ProtocolConfig)
-
-func WithProtocol_Name(name string) ProtocolOption {
- return func(cfg *ProtocolConfig) {
- cfg.Name = name
- }
-}
-
-func WithProtocol_Ip(ip string) ProtocolOption {
- return func(cfg *ProtocolConfig) {
- cfg.Ip = ip
- }
-}
-
-func WithProtocol_Port(port string) ProtocolOption {
- return func(cfg *ProtocolConfig) {
- cfg.Port = port
- }
-}
-
-func WithProtocol_Params(params interface{}) ProtocolOption {
- return func(cfg *ProtocolConfig) {
- cfg.Params = params
- }
-}
-
-func WithProtocol_MaxServerSendMsgSize(size string) ProtocolOption {
- return func(cfg *ProtocolConfig) {
- cfg.MaxServerSendMsgSize = size
- }
-}
-
-func WithProtocol_MaxServerRecvMsgSize(size string) ProtocolOption {
- return func(cfg *ProtocolConfig) {
- cfg.MaxServerRecvMsgSize = size
- }
-}
diff --git a/global/registry_config.go b/global/registry_config.go
index f96ff5250..783dccd2b 100644
--- a/global/registry_config.go
+++ b/global/registry_config.go
@@ -44,101 +44,3 @@ type RegistryConfig struct {
func DefaultRegistryConfig() *RegistryConfig {
return &RegistryConfig{}
}
-
-type RegistryOption func(*RegistryConfig)
-
-func WithRegistry_Protocol(protocol string) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.Protocol = protocol
- }
-}
-
-func WithRegistry_Timeout(timeout string) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.Timeout = timeout
- }
-}
-
-func WithRegistry_Group(group string) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.Group = group
- }
-}
-
-func WithRegistry_Namespace(namespace string) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.Namespace = namespace
- }
-}
-
-func WithRegistry_TTL(ttl string) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.TTL = ttl
- }
-}
-
-func WithRegistry_Address(address string) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.Address = address
- }
-}
-
-func WithRegistry_Username(name string) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.Username = name
- }
-}
-
-func WithRegistry_Password(password string) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.Password = password
- }
-}
-
-func WithRegistry_Simplified(flag bool) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.Simplified = flag
- }
-}
-
-func WithRegistry_Preferred(flag bool) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.Preferred = flag
- }
-}
-
-func WithRegistry_Zone(zone string) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.Zone = zone
- }
-}
-
-func WithRegistry_Weight(weight int64) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.Weight = weight
- }
-}
-
-func WithRegistry_Params(params map[string]string) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.Params = params
- }
-}
-
-func WithRegistry_RegistryType(typ string) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.RegistryType = typ
- }
-}
-
-func WithRegistry_UseAsMetaReport(flag bool) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.UseAsMetaReport = flag
- }
-}
-
-func WithRegistry_UseAsConfigCenter(flag bool) RegistryOption {
- return func(cfg *RegistryConfig) {
- cfg.UseAsConfigCenter = flag
- }
-}
diff --git a/global/tls_config.go b/global/tls_config.go
index f6b1e56e7..3b30d199b 100644
--- a/global/tls_config.go
+++ b/global/tls_config.go
@@ -18,6 +18,11 @@
package global
// TLSConfig tls config
+//
+// # Experimental
+//
+// Notice: This struct is EXPERIMENTAL and may be changed or removed in a
+// later release.
type TLSConfig struct {
CACertFile string `yaml:"ca-cert-file" json:"ca-cert-file" property:"ca-cert-file"`
TLSCertFile string `yaml:"tls-cert-file" json:"tls-cert-file" property:"tls-cert-file"`
diff --git a/global/tracing_config.go b/global/tracing_config.go
index d6d453ffb..1429c8c3c 100644
--- a/global/tracing_config.go
+++ b/global/tracing_config.go
@@ -24,29 +24,3 @@ type TracingConfig struct {
Address string `yaml:"address" json:"address,omitempty" property:"address"`
UseAgent *bool `default:"false" yaml:"use-agent" json:"use-agent,omitempty" property:"use-agent"`
}
-
-type TracingOption func(*TracingConfig)
-
-func WithTracing_Name(name string) TracingOption {
- return func(cfg *TracingConfig) {
- cfg.Name = name
- }
-}
-
-func WithTracing_ServiceName(name string) TracingOption {
- return func(cfg *TracingConfig) {
- cfg.ServiceName = name
- }
-}
-
-func WithTracing_Address(address string) TracingOption {
- return func(cfg *TracingConfig) {
- cfg.Address = address
- }
-}
-
-func WithTracing_UseAgent(flag bool) TracingOption {
- return func(cfg *TracingConfig) {
- cfg.UseAgent = &flag
- }
-}
diff --git a/go.mod b/go.mod
index 1c6c70545..048d68db7 100644
--- a/go.mod
+++ b/go.mod
@@ -17,6 +17,7 @@ require (
github.com/dubbogo/go-zookeeper v1.0.4-0.20211212162352-f9d2183d89d5
github.com/dubbogo/gost v1.14.0
github.com/dubbogo/grpc-go v1.42.10
+ github.com/dubbogo/tools v1.0.9 // indirect
github.com/dubbogo/triple v1.2.2-rc3
github.com/dustin/go-humanize v1.0.1
github.com/emicklei/go-restful/v3 v3.10.1
diff --git a/protocol/options.go b/logger/options.go
similarity index 50%
copy from protocol/options.go
copy to logger/options.go
index 8741e256c..db80033dd 100644
--- a/protocol/options.go
+++ b/logger/options.go
@@ -15,109 +15,87 @@
* limitations under the License.
*/
-package protocol
-
-import (
- "fmt"
- "strconv"
-)
+package logger
import (
"dubbo.apache.org/dubbo-go/v3/global"
)
type Options struct {
- Protocol *global.ProtocolConfig
-
- ID string
+ Logger *global.LoggerConfig
}
func defaultOptions() *Options {
- return &Options{Protocol: global.DefaultProtocolConfig()}
+ return &Options{Logger: global.DefaultLoggerConfig()}
}
func NewOptions(opts ...Option) *Options {
- defOpts := defaultOptions()
+ Options := defaultOptions()
for _, opt := range opts {
- opt(defOpts)
- }
-
- if defOpts.Protocol.Name == "" {
- panic(fmt.Sprintf("Please specify registry, eg. WithTriple()"))
+ opt(Options)
}
- if defOpts.ID == "" {
- defOpts.ID = defOpts.Protocol.Name
- }
-
- return defOpts
+ return Options
}
type Option func(*Options)
-func WithDubbo() Option {
- return func(opts *Options) {
- opts.Protocol.Name = "dubbo"
- }
-}
-
-func WithGRPC() Option {
+func WithLogrus() Option {
return func(opts *Options) {
- opts.Protocol.Name = "grpc"
+ opts.Logger.Driver = "logrus"
}
}
-func WithJSONRPC() Option {
+func WithZap() Option {
return func(opts *Options) {
- opts.Protocol.Name = "jsonrpc"
+ opts.Logger.Driver = "zap"
}
}
-func WithREST() Option {
+func WithLevel(level string) Option {
return func(opts *Options) {
- opts.Protocol.Name = "rest"
+ opts.Logger.Level = level
}
}
-func WithTriple() Option {
+func WithFormat(format string) Option {
return func(opts *Options) {
- opts.Protocol.Name = "tri"
+ opts.Logger.Format = format
}
}
-// WithID specifies the id of protocol.Options. Then you could configure server.WithProtocolIDs and
-// server.WithServer_ProtocolIDs to specify which protocol you need to use in multi-protocols scenario.
-func WithID(id string) Option {
+func WithAppender(appender string) Option {
return func(opts *Options) {
- opts.ID = id
+ opts.Logger.Appender = appender
}
}
-func WithIp(ip string) Option {
+func WithFileName(name string) Option {
return func(opts *Options) {
- opts.Protocol.Ip = ip
+ opts.Logger.File.Name = name
}
}
-func WithPort(port int) Option {
+func WithFileMaxSize(size int) Option {
return func(opts *Options) {
- opts.Protocol.Port = strconv.Itoa(port)
+ opts.Logger.File.MaxSize = size
}
}
-func WithParams(params interface{}) Option {
+func WithFileMaxBackups(backups int) Option {
return func(opts *Options) {
- opts.Protocol.Params = params
+ opts.Logger.File.MaxBackups = backups
}
}
-func WithMaxServerSendMsgSize(size int) Option {
+func WithFileMaxAge(age int) Option {
return func(opts *Options) {
- opts.Protocol.MaxServerSendMsgSize = strconv.Itoa(size)
+ opts.Logger.File.MaxAge = age
}
}
-func WithMaxServerRecvMsgSize(size int) Option {
+func WithFileCompress() Option {
return func(opts *Options) {
- opts.Protocol.MaxServerRecvMsgSize = strconv.Itoa(size)
+ b := true
+ opts.Logger.File.Compress = &b
}
}
diff --git a/metadata/options.go b/metadata/options.go
new file mode 100644
index 000000000..bec1fa91a
--- /dev/null
+++ b/metadata/options.go
@@ -0,0 +1,104 @@
+/*
+ * 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 metadata
+
+import (
+ "strconv"
+ "strings"
+ "time"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "dubbo.apache.org/dubbo-go/v3/global"
+)
+
+type Options struct {
+ Metadata *global.MetadataReportConfig
+}
+
+func defaultOptions() *Options {
+ return &Options{Metadata: global.DefaultMetadataReportConfig()}
+}
+
+func NewOptions(opts ...Option) *Options {
+ metaOptions := defaultOptions()
+ for _, opt := range opts {
+ opt(metaOptions)
+ }
+ return metaOptions
+}
+
+type Option func(*Options)
+
+func WithZookeeper() Option {
+ return func(opts *Options) {
+ opts.Metadata.Protocol = constant.ZookeeperKey
+ }
+}
+
+func WithNacos() Option {
+ return func(opts *Options) {
+ opts.Metadata.Protocol = constant.NacosKey
+ }
+}
+
+func WithEtcdV3() Option {
+ return func(opts *Options) {
+ opts.Metadata.Protocol = constant.EtcdV3Key
+ }
+}
+
+func WithAddress(address string) Option {
+ return func(opts *Options) {
+ if i := strings.Index(address, "://"); i > 0 {
+ opts.Metadata.Protocol = address[0:i]
+ }
+ opts.Metadata.Address = address
+ }
+}
+
+func WithUsername(username string) Option {
+ return func(opts *Options) {
+ opts.Metadata.Username = username
+ }
+}
+
+func WithPassword(password string) Option {
+ return func(opts *Options) {
+ opts.Metadata.Password = password
+ }
+}
+
+func WithTimeout(timeout time.Duration) Option {
+ return func(opts *Options) {
+ opts.Metadata.Timeout = strconv.Itoa(int(timeout.Milliseconds()))
+ }
+}
+
+func WithGroup(group string) Option {
+ return func(opts *Options) {
+ opts.Metadata.Group = group
+ }
+}
+
+func WithNamespace(namespace string) Option {
+ return func(opts *Options) {
+ opts.Metadata.Namespace = namespace
+ }
+}
diff --git a/metrics/options.go b/metrics/options.go
new file mode 100644
index 000000000..e51d56c7d
--- /dev/null
+++ b/metrics/options.go
@@ -0,0 +1,125 @@
+/*
+ * 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 metrics
+
+import (
+ "strconv"
+ "time"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/global"
+)
+
+type Options struct {
+ Metric *global.MetricConfig
+}
+
+func defaultOptions() *Options {
+ return &Options{Metric: global.DefaultMetricConfig()}
+}
+
+func NewOptions(opts ...Option) *Options {
+ MetricOptions := defaultOptions()
+ for _, opt := range opts {
+ opt(MetricOptions)
+ }
+ return MetricOptions
+}
+
+type Option func(*Options)
+
+func WithAggregationEnabled() Option {
+ return func(opts *Options) {
+ enabled := true
+ opts.Metric.Aggregation.Enabled = &enabled
+ }
+}
+
+func WithAggregationBucketNum(num int) Option {
+ return func(opts *Options) {
+ opts.Metric.Aggregation.BucketNum = num
+ }
+}
+
+func WithAggregationTimeWindowSeconds(seconds int) Option {
+ return func(opts *Options) {
+ opts.Metric.Aggregation.TimeWindowSeconds = seconds
+ }
+}
+
+func WithPrometheus() Option {
+ return func(opts *Options) {
+ opts.Metric.Protocol = "prometheus"
+ }
+}
+
+func WithPrometheusExporterEnabled() Option {
+ return func(opts *Options) {
+ enabled := true
+ opts.Metric.Prometheus.Exporter.Enabled = &enabled
+ }
+}
+
+func WithPrometheusGatewayUrl(url string) Option {
+ return func(opts *Options) {
+ opts.Metric.Prometheus.Pushgateway.BaseUrl = url
+ }
+}
+
+func WithPrometheusGatewayJob(job string) Option {
+ return func(opts *Options) {
+ opts.Metric.Prometheus.Pushgateway.Job = job
+ }
+}
+
+func WithPrometheusGatewayUsername(username string) Option {
+ return func(opts *Options) {
+ opts.Metric.Prometheus.Pushgateway.Username = username
+ }
+}
+
+func WithPrometheusGatewayPassword(password string) Option {
+ return func(opts *Options) {
+ opts.Metric.Prometheus.Pushgateway.Password = password
+ }
+}
+func WithPrometheusGatewayInterval(interval time.Duration) Option {
+ return func(opts *Options) {
+ opts.Metric.Prometheus.Pushgateway.PushInterval = int(interval.Seconds())
+ }
+}
+
+func WithEnabled() Option {
+ return func(opts *Options) {
+ b := true
+ opts.Metric.Enable = &b
+ }
+}
+
+func WithPort(port int) Option {
+ return func(opts *Options) {
+ opts.Metric.Port = strconv.Itoa(port)
+ }
+}
+
+func WithPath(path string) Option {
+ return func(opts *Options) {
+ opts.Metric.Path = path
+ }
+}
diff --git a/options.go b/options.go
index 85159e57a..ab839748c 100644
--- a/options.go
+++ b/options.go
@@ -18,14 +18,19 @@
package dubbo
import (
- "github.com/dubbogo/gost/log/logger"
+ log "github.com/dubbogo/gost/log/logger"
)
import (
"dubbo.apache.org/dubbo-go/v3/common/constant"
"dubbo.apache.org/dubbo-go/v3/config"
+ "dubbo.apache.org/dubbo-go/v3/config_center"
"dubbo.apache.org/dubbo-go/v3/global"
"dubbo.apache.org/dubbo-go/v3/graceful_shutdown"
+ "dubbo.apache.org/dubbo-go/v3/logger"
+ "dubbo.apache.org/dubbo-go/v3/metadata"
+ "dubbo.apache.org/dubbo-go/v3/metrics"
+ "dubbo.apache.org/dubbo-go/v3/otel/trace"
"dubbo.apache.org/dubbo-go/v3/protocol"
"dubbo.apache.org/dubbo-go/v3/registry"
)
@@ -82,8 +87,8 @@ func (rc *InstanceOptions) init(opts ...InstanceOption) error {
return err
}
if err := rcCompat.ConfigCenter.Init(rcCompat); err != nil {
- logger.Infof("[Config Center] Config center doesn't start")
- logger.Debugf("config center doesn't start because %s", err)
+ log.Infof("[Config Center] Config center doesn't start")
+ log.Debugf("config center doesn't start because %s", err)
} else {
if err = rcCompat.Logger.Init(); err != nil { // init logger using config from config center again
return err
@@ -242,74 +247,48 @@ func WithRegistry(opts ...registry.Option) InstanceOption {
}
}
-//func WithConfigCenter(opts ...global.CenterOption) InstanceOption {
-// ccCfg := new(global.CenterConfig)
-// for _, opt := range opts {
-// opt(ccCfg)
-// }
-//
-// return func(cfg *InstanceOptions) {
-// cfg.ConfigCenter = ccCfg
-// }
-//}
+func WithTracing(opts ...trace.Option) InstanceOption {
+ traceOpts := trace.NewOptions(opts...)
-//func WithMetadataReport(opts ...global.MetadataReportOption) InstanceOption {
-// mrCfg := new(global.MetadataReportConfig)
-// for _, opt := range opts {
-// opt(mrCfg)
-// }
-//
-// return func(cfg *InstanceOptions) {
-// cfg.MetadataReport = mrCfg
-// }
-//}
+ return func(insOpts *InstanceOptions) {
+ if insOpts.Tracing == nil {
+ insOpts.Tracing = make(map[string]*global.TracingConfig)
+ }
+ insOpts.Tracing[traceOpts.ID] = traceOpts.Tracing
+ }
+}
-//func WithConsumer(opts ...global.ConsumerOption) InstanceOption {
-// conCfg := new(global.ConsumerConfig)
-// for _, opt := range opts {
-// opt(conCfg)
-// }
-//
-// return func(cfg *InstanceOptions) {
-// cfg.Consumer = conCfg
-// }
-//}
+func WithConfigCenter(opts ...config_center.Option) InstanceOption {
+ configOpts := config_center.NewOptions(opts...)
-//func WithMetric(opts ...global.MetricOption) InstanceOption {
-// meCfg := new(global.MetricConfig)
-// for _, opt := range opts {
-// opt(meCfg)
-// }
-//
-// return func(cfg *InstanceOptions) {
-// cfg.Metric = meCfg
-// }
-//}
+ return func(cfg *InstanceOptions) {
+ cfg.ConfigCenter = configOpts.Center
+ }
+}
-//func WithTracing(key string, opts ...global.TracingOption) InstanceOption {
-// traCfg := new(global.TracingConfig)
-// for _, opt := range opts {
-// opt(traCfg)
-// }
-//
-// return func(cfg *InstanceOptions) {
-// if cfg.Tracing == nil {
-// cfg.Tracing = make(map[string]*global.TracingConfig)
-// }
-// cfg.Tracing[key] = traCfg
-// }
-//}
+func WithMetadataReport(opts ...metadata.Option) InstanceOption {
+ metadataOpts := metadata.NewOptions(opts...)
-//func WithLogger(opts ...global.LoggerOption) InstanceOption {
-// logCfg := new(global.LoggerConfig)
-// for _, opt := range opts {
-// opt(logCfg)
-// }
-//
-// return func(cfg *InstanceOptions) {
-// cfg.Logger = logCfg
-// }
-//}
+ return func(cfg *InstanceOptions) {
+ cfg.MetadataReport = metadataOpts.Metadata
+ }
+}
+
+func WithMetric(opts ...metrics.Option) InstanceOption {
+ metricOpts := metrics.NewOptions(opts...)
+
+ return func(cfg *InstanceOptions) {
+ cfg.Metric = metricOpts.Metric
+ }
+}
+
+func WithLogger(opts ...logger.Option) InstanceOption {
+ loggerOpts := logger.NewOptions(opts...)
+
+ return func(cfg *InstanceOptions) {
+ cfg.Logger = loggerOpts.Logger
+ }
+}
func WithShutdown(opts ...graceful_shutdown.Option) InstanceOption {
sdOpts := graceful_shutdown.NewOptions(opts...)
diff --git a/protocol/options.go b/otel/trace/options.go
similarity index 53%
copy from protocol/options.go
copy to otel/trace/options.go
index 8741e256c..6311bf6bb 100644
--- a/protocol/options.go
+++ b/otel/trace/options.go
@@ -15,11 +15,10 @@
* limitations under the License.
*/
-package protocol
+package trace
import (
"fmt"
- "strconv"
)
import (
@@ -27,13 +26,13 @@ import (
)
type Options struct {
- Protocol *global.ProtocolConfig
+ Tracing *global.TracingConfig
ID string
}
func defaultOptions() *Options {
- return &Options{Protocol: global.DefaultProtocolConfig()}
+ return &Options{Tracing: &global.TracingConfig{}}
}
func NewOptions(opts ...Option) *Options {
@@ -42,11 +41,11 @@ func NewOptions(opts ...Option) *Options {
opt(defOpts)
}
- if defOpts.Protocol.Name == "" {
- panic(fmt.Sprintf("Please specify registry, eg. WithTriple()"))
+ if defOpts.Tracing.Name == "" {
+ panic(fmt.Sprintf("Please specify the tracing system to use, eg. WithZipkin()"))
}
if defOpts.ID == "" {
- defOpts.ID = defOpts.Protocol.Name
+ defOpts.ID = defOpts.Tracing.Name
}
return defOpts
@@ -54,70 +53,51 @@ func NewOptions(opts ...Option) *Options {
type Option func(*Options)
-func WithDubbo() Option {
- return func(opts *Options) {
- opts.Protocol.Name = "dubbo"
- }
-}
-
-func WithGRPC() Option {
- return func(opts *Options) {
- opts.Protocol.Name = "grpc"
- }
-}
-
-func WithJSONRPC() Option {
- return func(opts *Options) {
- opts.Protocol.Name = "jsonrpc"
- }
-}
-
-func WithREST() Option {
+func WithID(id string) Option {
return func(opts *Options) {
- opts.Protocol.Name = "rest"
+ opts.ID = id
}
}
-func WithTriple() Option {
+func WithZipkin() Option {
return func(opts *Options) {
- opts.Protocol.Name = "tri"
+ opts.Tracing.Name = "zipkin"
}
}
-// WithID specifies the id of protocol.Options. Then you could configure server.WithProtocolIDs and
-// server.WithServer_ProtocolIDs to specify which protocol you need to use in multi-protocols scenario.
-func WithID(id string) Option {
+func WithJaeger() Option {
return func(opts *Options) {
- opts.ID = id
+ opts.Tracing.Name = "jaeger"
}
}
-func WithIp(ip string) Option {
+func WithOltp() Option {
return func(opts *Options) {
- opts.Protocol.Ip = ip
+ opts.Tracing.Name = "oltp"
}
}
-func WithPort(port int) Option {
+func WithStdout() Option {
return func(opts *Options) {
- opts.Protocol.Port = strconv.Itoa(port)
+ opts.Tracing.Name = "stdout"
}
}
-func WithParams(params interface{}) Option {
+func WithServiceName(name string) Option {
return func(opts *Options) {
- opts.Protocol.Params = params
+ opts.Tracing.ServiceName = name
}
}
-func WithMaxServerSendMsgSize(size int) Option {
+func WithAddress(address string) Option {
return func(opts *Options) {
- opts.Protocol.MaxServerSendMsgSize = strconv.Itoa(size)
+ opts.Tracing.Address = address
}
}
-func WithMaxServerRecvMsgSize(size int) Option {
+func WithUseAgent() Option {
return func(opts *Options) {
- opts.Protocol.MaxServerRecvMsgSize = strconv.Itoa(size)
+ b := true
+ opts.Tracing.UseAgent = &b
}
}
diff --git a/protocol/options.go b/protocol/options.go
index 8741e256c..58683af5b 100644
--- a/protocol/options.go
+++ b/protocol/options.go
@@ -18,7 +18,6 @@
package protocol
import (
- "fmt"
"strconv"
)
@@ -42,11 +41,13 @@ func NewOptions(opts ...Option) *Options {
opt(defOpts)
}
- if defOpts.Protocol.Name == "" {
- panic(fmt.Sprintf("Please specify registry, eg. WithTriple()"))
- }
if defOpts.ID == "" {
- defOpts.ID = defOpts.Protocol.Name
+ if defOpts.Protocol.Name == "" {
+ // should be the same as default value of config.ProtocolConfig.Protocol
+ defOpts.ID = "tri"
+ } else {
+ defOpts.ID = defOpts.Protocol.Name
+ }
}
return defOpts
@@ -60,12 +61,6 @@ func WithDubbo() Option {
}
}
-func WithGRPC() Option {
- return func(opts *Options) {
- opts.Protocol.Name = "grpc"
- }
-}
-
func WithJSONRPC() Option {
return func(opts *Options) {
opts.Protocol.Name = "jsonrpc"
diff --git a/registry/options.go b/registry/options.go
index 563438a7a..0ff58654f 100644
--- a/registry/options.go
+++ b/registry/options.go
@@ -19,6 +19,7 @@ package registry
import (
"fmt"
+ "strings"
"time"
)
@@ -27,8 +28,6 @@ import (
"dubbo.apache.org/dubbo-go/v3/global"
)
-var defaultIDMap = map[string]string{}
-
type Options struct {
Registry *global.RegistryConfig
@@ -63,7 +62,6 @@ func WithEtcdV3() Option {
return func(opts *Options) {
// todo(DMwangnima): move etcdv3 to constant
opts.Registry.Protocol = "etcdv3"
-
}
}
@@ -87,8 +85,7 @@ func WithXDS() Option {
func WithZookeeper() Option {
return func(opts *Options) {
- // todo(DMwangnima): move zookeeper to constant
- opts.Registry.Protocol = "zookeeper"
+ opts.Registry.Protocol = constant.ZookeeperKey
}
}
@@ -126,6 +123,9 @@ func WithTTL(ttl time.Duration) Option {
func WithAddress(address string) Option {
return func(opts *Options) {
+ if i := strings.Index(address, "://"); i > 0 {
+ opts.Registry.Protocol = address[0:i]
+ }
opts.Registry.Address = address
}
}