AlexStocks commented on code in PR #3320: URL: https://github.com/apache/dubbo-go/pull/3320#discussion_r3241450305
########## instance_options_init.go: ########## @@ -0,0 +1,722 @@ +/* + * 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 dubbo + +import ( + "fmt" + "net/url" + "strconv" + "strings" +) + +import ( + getty "github.com/apache/dubbo-getty" + + "github.com/creasty/defaults" + + "github.com/dubbogo/gost/log/logger" + + "github.com/knadh/koanf" + + "go.opentelemetry.io/otel" +) + +import ( + "dubbo.apache.org/dubbo-go/v3/common" + commonCfg "dubbo.apache.org/dubbo-go/v3/common/config" + "dubbo.apache.org/dubbo-go/v3/common/constant" + "dubbo.apache.org/dubbo-go/v3/common/extension" + "dubbo.apache.org/dubbo-go/v3/config_center" + aslimiter "dubbo.apache.org/dubbo-go/v3/filter/adaptivesvc/limiter" + "dubbo.apache.org/dubbo-go/v3/global" + "dubbo.apache.org/dubbo-go/v3/internal" + "dubbo.apache.org/dubbo-go/v3/metrics" + metricsConfigCenter "dubbo.apache.org/dubbo-go/v3/metrics/config_center" + "dubbo.apache.org/dubbo-go/v3/otel/trace" + "dubbo.apache.org/dubbo-go/v3/remoting" +) + +func (rc *InstanceOptions) finalizeGlobalOptionsWithRuntimeActivation(activateRuntime bool) error { + if err := rc.initGlobalApplication(); err != nil { + return err + } + if err := rc.initGlobalCustom(); err != nil { + return err + } + if err := rc.initGlobalProtocols(); err != nil { + return err + } + if err := rc.initGlobalRegistries(); err != nil { + return err + } + if err := rc.initGlobalMetrics(activateRuntime); err != nil { + return err + } + if err := rc.initGlobalOtel(activateRuntime); err != nil { + return err + } + if err := rc.initGlobalRouters(); err != nil { + return err + } + for _, tracingConfig := range rc.Tracing { + if tracingConfig == nil { + continue + } + if err := defaults.Set(tracingConfig); err != nil { + return err + } + if err := commonCfg.Verify(tracingConfig); err != nil { + return err + } + } + if err := rc.initGlobalProvider(activateRuntime); err != nil { + return err + } + if err := rc.initGlobalConsumer(); err != nil { + return err + } + return rc.initGlobalShutdown() +} + +func (rc *InstanceOptions) initGlobalApplication() error { + if rc.Application == nil { + rc.Application = global.DefaultApplicationConfig() + } + if err := defaults.Set(rc.Application); err != nil { + return err + } + if rc.Application.Name == "" { + rc.Application.Name = constant.DefaultDubboApp + } + return commonCfg.Verify(rc.Application) +} + +func (rc *InstanceOptions) initGlobalCustom() error { + if rc.Custom == nil { + rc.Custom = global.DefaultCustomConfig() + } + if rc.Custom.ConfigMap == nil { + rc.Custom.ConfigMap = make(map[string]any) + } + if err := defaults.Set(rc.Custom); err != nil { + return err + } + return commonCfg.Verify(rc.Custom) +} + +func (rc *InstanceOptions) initGlobalProtocols() error { + if len(rc.Protocols) <= 0 { + rc.Protocols = map[string]*global.ProtocolConfig{ + constant.TriProtocol: {}, + } + } + for key, protocolConfig := range rc.Protocols { + if protocolConfig == nil { + protocolConfig = &global.ProtocolConfig{} + rc.Protocols[key] = protocolConfig + } + if err := initGlobalProtocol(protocolConfig); err != nil { + return err + } + } + return nil +} + +func initGlobalProtocol(protocolConfig *global.ProtocolConfig) error { + if err := defaults.Set(protocolConfig); err != nil { + return err + } + if protocolConfig.Name == "" { + protocolConfig.Name = constant.TriProtocol + } + if protocolConfig.Port == "" { + protocolConfig.Port = constant.DefaultTripleProtocolPort + } + if protocolConfig.TripleConfig == nil { + protocolConfig.TripleConfig = global.DefaultTripleConfig() + } else { + if protocolConfig.TripleConfig.Http3 == nil { + protocolConfig.TripleConfig.Http3 = global.DefaultHttp3Config() + } + if protocolConfig.TripleConfig.Cors == nil { + protocolConfig.TripleConfig.Cors = global.DefaultCorsConfig() + } + if protocolConfig.TripleConfig.OpenAPI == nil { + protocolConfig.TripleConfig.OpenAPI = global.DefaultOpenAPIConfig() Review Comment: [P1] 这里在用户提供部分 OpenAPI 配置时只处理 nil 子配置并调用 Init(),不会把 DefaultOpenAPIConfig() 里的 InfoTitle、InfoVersion、DefaultConsumesMediaTypes、Settings 等默认字段补回来。配置中心只下发 enabled/path 这类局部配置时,OpenAPI 文档会带空 title/version,schema resolver 也可能拿到空 media types。建议先用 default := global.DefaultOpenAPIConfig() 作为基底,再把用户显式字段覆盖上去,或给 OpenAPIConfig 增加完整的 Init/default 合并逻辑,并补一个只配置 enabled/path 的测试。 -- 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]
