DMwangnima commented on code in PR #2534:
URL: https://github.com/apache/dubbo-go/pull/2534#discussion_r1461290889
##########
metadata/options.go:
##########
@@ -44,73 +57,151 @@ func NewOptions(opts ...Option) *Options {
return metaOptions
}
+func (opts *Options) Init() error {
+ metadataOptions = opts
+ var err error
+ exportOnce.Do(func() {
+ if opts.metadataType != constant.RemoteMetadataStorageType {
+ exporter := &ServiceExporter{service: metadataService,
opts: opts}
+ defer func() {
+ // TODO remove this recover func,this just to
avoid some unit test failed,this will not happen in user side mostly
+ // config test -> metadata exporter -> dubbo
protocol/remoting -> config,cycle import will occur
+ // some day we fix the cycle import then can
remove this recover
+ if err := recover(); err != nil {
+ logger.Errorf("metadata export
failed,please check if dubbo protocol is imported, error: %v", err)
+ }
+ }()
+ err = exporter.Export()
+ }
+ })
+ return err
+}
+
type Option func(*Options)
-func WithZookeeper() Option {
- return func(opts *Options) {
- opts.Metadata.Protocol = constant.ZookeeperKey
+func WithAppName(app string) Option {
+ return func(options *Options) {
+ options.appName = app
}
}
-func WithNacos() Option {
- return func(opts *Options) {
- opts.Metadata.Protocol = constant.NacosKey
+func WithMetadataType(typ string) Option {
+ return func(options *Options) {
+ options.metadataType = typ
}
}
-func WithEtcdV3() Option {
- return func(opts *Options) {
- opts.Metadata.Protocol = constant.EtcdV3Key
+func WithPort(port int) Option {
+ return func(options *Options) {
+ options.port = port
}
}
-func WithMetadata(meta string) Option {
- return func(opts *Options) {
- opts.Metadata.Protocol = meta
+type ReportOptions struct {
+ registryId string
+ *global.MetadataReportConfig
+}
+
+func (opts *ReportOptions) Init() error {
+ fac := extension.GetMetadataReportFactory(opts.Protocol)
+ if fac == nil {
+ logger.Errorf("no metadata report factory of protocol %s
found!", opts.Protocol)
+ return nil
+ }
+ url, err := toUrl(opts)
+ if err != nil {
+ logger.Errorf("metadata report create error %v", err)
+ return err
+ }
+ instances[opts.registryId] = &DelegateMetadataReport{instance:
fac.CreateMetadataReport(url)}
+ return nil
+}
+
+func defaultReportOptions() *ReportOptions {
+ return &ReportOptions{MetadataReportConfig:
global.DefaultMetadataReportConfig()}
+}
+
+func NewReportOptions(opts ...ReportOption) *ReportOptions {
+ reportOptions := defaultReportOptions()
+ for _, opt := range opts {
+ opt(reportOptions)
}
+ return reportOptions
}
-func WithAddress(address string) Option {
- return func(opts *Options) {
+type ReportOption func(*ReportOptions)
+
+func WithZookeeper() ReportOption {
+ return func(opts *ReportOptions) {
+ opts.Protocol = constant.ZookeeperKey
+ }
+}
+
+func WithNacos() ReportOption {
+ return func(opts *ReportOptions) {
+ opts.Protocol = constant.NacosKey
+ }
+}
+
+func WithEtcdV3() ReportOption {
+ return func(opts *ReportOptions) {
+ opts.Protocol = constant.EtcdV3Key
+ }
+}
+
+func WithProtocol(meta string) ReportOption {
+ return func(opts *ReportOptions) {
+ opts.Protocol = meta
+ }
+}
+
+func WithAddress(address string) ReportOption {
+ return func(opts *ReportOptions) {
if i := strings.Index(address, "://"); i > 0 {
- opts.Metadata.Protocol = address[0:i]
+ opts.Protocol = address[0:i]
Review Comment:
Please add a comment on WithAddress function to tell uses that this function
would set Protocol possibly.
--
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]