xjlgod commented on code in PR #650:
URL: 
https://github.com/apache/incubator-seata-go/pull/650#discussion_r1464992823


##########
pkg/saga/statemachine/statelang/parser/statemachine_parser.go:
##########
@@ -52,22 +41,118 @@ func (b BaseStateParser) GetString(stateName string, 
stateMap map[string]interfa
        return valueAsString, nil
 }
 
-func (b BaseStateParser) GetSlice(stateName string, stateMap 
map[string]interface{}, key string) ([]interface{}, error) {
+func (b BaseStateParser) GetStringOrDefault(stateMap map[string]interface{}, 
key string, defaultValue string) string {
        value := stateMap[key]
+       if value == nil {
+               return defaultValue
+       }
+
+       valueAsString, ok := value.(string)
+       if !ok {
+               return defaultValue
+       }
+       return valueAsString
+}
 
+func (b BaseStateParser) GetSlice(stateName string, stateMap 
map[string]interface{}, key string) ([]interface{}, error) {
+       value := stateMap[key]
        if value == nil {
                var result []interface{}
                return result, errors.New("State [" + stateName + "] " + key + 
" not exist")
        }
 
        valueAsSlice, ok := value.([]interface{})
        if !ok {
-               var result []interface{}
-               return result, errors.New("State [" + stateName + "] " + key + 
" illegal, required slice")
+               var slice []interface{}
+               return slice, errors.New("State [" + stateName + "] " + key + " 
illegal, required []interface{}")
        }
        return valueAsSlice, nil
 }
 
+func (b BaseStateParser) GetSliceOrDefault(stateMap map[string]interface{}, 
key string, defaultValue []interface{}) []interface{} {
+       value := stateMap[key]
+
+       if value == nil {
+               return defaultValue
+       }
+
+       valueAsSlice, ok := value.([]interface{})
+       if !ok {
+               return defaultValue
+       }
+       return valueAsSlice
+}
+
+func (b BaseStateParser) GetMapOrDefault(stateMap map[string]interface{}, key 
string, defaultValue map[string]interface{}) map[string]interface{} {
+       value := stateMap[key]
+
+       if value == nil {
+               return defaultValue
+       }
+
+       valueAsMap, ok := value.(map[string]interface{})
+       if !ok {
+               return defaultValue
+       }
+       return valueAsMap
+}
+
+func (b BaseStateParser) GetBool(stateName string, stateMap 
map[string]interface{}, key string) (bool, error) {

Review Comment:
   I modified it to keep unify now.



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