validateAndReplaceDataWithVariable validates the string for a global variable and replaces it. An error is returned if the string references an invalid global variable key
(val string, variables map[string]string)
| 72 | // validateAndReplaceDataWithVariable validates the string for a global variable and replaces it. An error |
| 73 | // is returned if the string references an invalid global variable key |
| 74 | func validateAndReplaceDataWithVariable(val string, variables map[string]string) (string, error) { |
| 75 | matches := globalVariableRegex.FindAllStringSubmatch(val, -1) |
| 76 | var invalidKeys []string |
| 77 | for _, match := range matches { |
| 78 | varValue, ok := variables[match[1]] |
| 79 | if !ok { |
| 80 | invalidKeys = append(invalidKeys, match[1]) |
| 81 | } else { |
| 82 | val = strings.Replace(val, match[0], varValue, -1) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | if len(invalidKeys) > 0 { |
| 87 | return val, &InvalidKeysError{Keys: invalidKeys} |
| 88 | } |
| 89 | |
| 90 | return val, nil |
| 91 | } |
no outgoing calls