justxuewei commented on a change in pull request #1754:
URL: https://github.com/apache/dubbo-go/pull/1754#discussion_r808834592



##########
File path: config/config_loader_options.go
##########
@@ -180,3 +188,52 @@ func checkFileSuffix(suffix string) error {
        }
        return errors.Errorf("no support file suffix: %s", suffix)
 }
+
+//resolverFilePath resolver file path
+// eg: give a ./conf/dubbogo.yaml return dubbogo and yaml
+func resolverFilePath(path string) (name, suffix string) {
+       paths := strings.Split(path, "/")
+       fileName := strings.Split(paths[len(paths)-1], ".")
+       if len(fileName) < 2 {
+               return fileName[0], string(file.YAML)
+       }
+       return fileName[0], fileName[1]
+}
+
+//MergeConfig merge config file
+func (conf *loaderConf) MergeConfig(koan *koanf.Koanf) *koanf.Koanf {
+       var (
+               activeKoan *koanf.Koanf
+               activeConf *loaderConf
+       )
+       active := koan.String("dubbo.profiles.active")
+       active = getLegalActive(active)
+       logger.Infof("The following profiles are active: %s", active)
+       if defaultActive != active {
+               path := conf.getActiveFilePath(active)
+               if !pathExists(path) {
+                       logger.Debugf("Config file:%s not exist skip config 
merge", path)
+                       return koan
+               }
+               activeConf = NewLoaderConf(WithPath(path))
+               activeKoan = GetConfigResolver(activeConf)
+               if err := koan.Merge(activeKoan); err != nil {
+                       logger.Debugf("Config merge err %s", err)
+               }
+       }
+       return koan
+}
+
+func (conf *loaderConf) getActiveFilePath(active string) string {
+       suffix := constant.DotSeparator + conf.suffix
+       return strings.ReplaceAll(conf.path, suffix, "") + "-" + active + suffix
+}
+
+func pathExists(path string) bool {
+       if _, err := os.Stat(path); err == nil {
+               return true
+       } else if os.IsNotExist(err) {
+               return false
+       }
+       return false

Review comment:
       Why return false twice here? Maybe you want to do something on the 
second branch?




-- 
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]

Reply via email to