DMwangnima commented on code in PR #2447:
URL: https://github.com/apache/dubbo-go/pull/2447#discussion_r1356450843
##########
otel/trace/options.go:
##########
@@ -0,0 +1,103 @@
+/*
Review Comment:
**config.OtelConfig** and **config.TracingConfig** should be considered well
with @ev1lQuark.
##########
registry/options.go:
##########
@@ -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[1:i]
Review Comment:
This should be ```address[0:i]```?
##########
protocol/options.go:
##########
@@ -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 == "" {
Review Comment:
Not just **ID**, **Name** should be set as well?
I think this logic should be:
```go
if defOpts.Protocol.Name == "" {
defOpts.Protocol.Name = "tri"
}
if defOpts.ID == "" {
defOpts.ID = defOpts.Protocol.Name
}
```
##########
metadata/options.go:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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 (
+ "strings"
+)
+
+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 WithEtcd() Option {
Review Comment:
EtcdV3 for unification.
##########
metrics/options.go:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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 (
+ "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 WithPrometheusEnabled() 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 int) Option {
+ return func(opts *Options) {
+ opts.Metric.Prometheus.Pushgateway.PushInterval = interval
+ }
+}
+
+func WithEnabled() Option {
+ return func(opts *Options) {
+ b := true
+ opts.Metric.Enable = &b
+ }
+}
+
+func WithPort(port string) Option {
+ return func(opts *Options) {
+ opts.Metric.Port = port
+ }
+}
+
+func WithPath(path string) Option {
+ return func(opts *Options) {
+ opts.Metric.Path = path
+ }
+}
+
+func WithProtocol(protocol string) Option {
Review Comment:
Is this field related to the configuration above? For instance,
```WithProtocol("prometheus")``` could be deduced from
```WithPrometheusEnabled()```.
By the way, protocol could be enumerated. Please
see(https://github.com/apache/dubbo-go/blob/8b041402f7d7cebb82effc0f6213f3f19f17c9ed/common/constant/metric.go#L47).
Maybe we should talk with @FoghostCn.
##########
metadata/options.go:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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 (
+ "strings"
+)
+
+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 WithEtcd() 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[1: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 string) Option {
Review Comment:
This should be
```go
func WithTimeout(timeout time.Duration) Option {
return func(opts *Options) {
opts.Metadata.Timeout = timeout.String()
}
}
```
##########
logger/options.go:
##########
@@ -0,0 +1,137 @@
+/*
Review Comment:
LoggerConfig has many default values so that ```WithZap(), WithLevelInfo(),
WithFormatText(), WithAppenderConsole()``` could be deleted?
##########
config_center/options.go:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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 (
+ "strings"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "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 WithFile() Option {
+ return func(opts *Options) {
+ opts.Center.Protocol = constant.FileKey
+ }
+}
+
+func WithAddress(address string) Option {
+ return func(opts *Options) {
+ if i := strings.Index(address, "://"); i > 0 {
+ opts.Center.Protocol = address[1: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 string) Option {
Review Comment:
This should be
```go
func WithTimeout(timeout time.Duration) Option {
return func(opts *Options) {
opts.Center.Timeout = timeout
}
}
```
##########
config_center/options.go:
##########
@@ -0,0 +1,132 @@
+/*
+ * 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 (
+ "strings"
+)
+
+import (
+ "dubbo.apache.org/dubbo-go/v3/common/constant"
+ "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 WithFile() Option {
+ return func(opts *Options) {
+ opts.Center.Protocol = constant.FileKey
+ }
+}
+
+func WithAddress(address string) Option {
+ return func(opts *Options) {
+ if i := strings.Index(address, "://"); i > 0 {
+ opts.Center.Protocol = address[1: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 string) Option {
+ return func(opts *Options) {
+ opts.Center.Timeout = timeout
+ }
+}
+
+func WithParams(params map[string]string) Option {
+ return func(opts *Options) {
+ opts.Center.Params = params
+ }
+}
+
+func WithFileExtension(extension string) Option {
Review Comment:
This field could be enumerated. Please see
(https://github.com/apache/dubbo-go/blob/8b041402f7d7cebb82effc0f6213f3f19f17c9ed/common/constant/file/suffix.go#L22).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]