flypiggyyoyoyo commented on code in PR #871:
URL: 
https://github.com/apache/incubator-seata-go/pull/871#discussion_r2314951373


##########
pkg/saga/statemachine/engine/config/default_statemachine_config.go:
##########
@@ -364,28 +359,27 @@ func (c *DefaultStateMachineConfig) LoadConfig(configPath 
string) error {
                return fmt.Errorf("failed to read config file: path=%s, 
error=%w", configPath, err)
        }
 
-       parser := parser.NewStateMachineConfigParser()
-       smo, err := parser.Parse(content)
-       if err != nil {
-               return fmt.Errorf("failed to parse state machine definition: 
path=%s, error=%w", configPath, err)
-       }
-
        var configFileParams ConfigFileParams
-       if err := json.Unmarshal(content, &configFileParams); err != nil {
+       ext := strings.ToLower(filepath.Ext(configPath))
+
+       switch ext {
+       case ".json":
+               if err := json.Unmarshal(content, &configFileParams); err != 
nil {
+                       return fmt.Errorf("failed to unmarshal config file as 
JSON: %w", err)
+               }
+       case ".yaml", ".yml":
                if err := yaml.Unmarshal(content, &configFileParams); err != 
nil {
                        return fmt.Errorf("failed to unmarshal config file as 
YAML: %w", err)
-               } else {
-                       c.applyConfigFileParams(&configFileParams)
                }
-       } else {
-               c.applyConfigFileParams(&configFileParams)
-       }
-
-       if _, exists := c.stateMachineDefs[smo.Name]; exists {
-               return fmt.Errorf("state machine definition with name %s 
already exists", smo.Name)
+       default:
+               if err := json.Unmarshal(content, &configFileParams); err != 
nil {
+                       if err := yaml.Unmarshal(content, &configFileParams); 
err != nil {
+                               return fmt.Errorf("failed to unmarshal config 
file (unknown type): %w", err)
+                       }

Review Comment:
   Done. 



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