nanjiek commented on code in PR #3256:
URL: https://github.com/apache/dubbo-go/pull/3256#discussion_r2945525717
##########
cluster/router/polaris/router.go:
##########
@@ -53,14 +53,39 @@ var (
func newPolarisRouter(url *common.URL) (*polarisRouter, error) {
- // get application name from url param
applicationName := url.GetParam(constant.ApplicationKey, "")
+ // then try attribute (current storage path)
if applicationName == "" {
+ if appConfRaw, ok := url.GetAttribute(constant.ApplicationKey);
ok {
+ switch appConf := appConfRaw.(type) {
+ case *global.ApplicationConfig:
+ if appConf != nil {
+ applicationName = appConf.Name
+ }
+ case global.ApplicationConfig:
+ applicationName = appConf.Name
+ }
+ }
+ }
+ // fallback to SubURL
+ if applicationName == "" && url.SubURL != nil {
applicationName = url.SubURL.GetParam(constant.ApplicationKey,
"")
if applicationName == "" {
- return nil, fmt.Errorf("polaris router must set
application name")
+ if appConfRaw, ok :=
url.SubURL.GetAttribute(constant.ApplicationKey); ok {
+ switch appConf := appConfRaw.(type) {
+ case *global.ApplicationConfig:
+ if appConf != nil {
+ applicationName = appConf.Name
+ }
+ case global.ApplicationConfig:
+ applicationName = appConf.Name
+ }
+ }
Review Comment:
代码有明显复用,可以抽离,降低主函数的复杂度。
--
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]