|
21 | 21 | mapType = reflect.TypeOf(&structpb.Struct{}) |
22 | 22 | ) |
23 | 23 |
|
24 | | -// ReplacePlaceHoldersVariables Replace those {{var}} placeholders to the runinfo variable. |
| 24 | +// ReplacePlaceHoldersVariables is a function that replaces placeholders in a |
| 25 | +// given string template with their corresponding values. The placeholders are |
| 26 | +// expected to be in the format `{{key}}`, where `key` is the identifier for a |
| 27 | +// value. |
| 28 | +// |
| 29 | +// The function first checks if the key in the placeholder has a prefix of |
| 30 | +// "body", "headers", or "files". If it does and both `rawEvent` and `headers` |
| 31 | +// are not nil, it attempts to retrieve the value for the key using the |
| 32 | +// `customparams.CelValue` function and returns the corresponding string |
| 33 | +// representation. If the key does not have any of the mentioned prefixes, the |
| 34 | +// function checks if the key exists in the `dico` map. If it does, the |
| 35 | +// function replaces the placeholder with the corresponding value from the |
| 36 | +// `dico` map. |
| 37 | +// |
| 38 | +// Parameters: |
| 39 | +// - template (string): The input string that may contain placeholders in the |
| 40 | +// format `{{key}}`. |
| 41 | +// - dico (map[string]string): A dictionary mapping keys to their corresponding |
| 42 | +// string values. If a placeholder's key is found in this dictionary, it will |
| 43 | +// be replaced with the corresponding value. |
| 44 | +// - rawEvent (any): The raw event data that may be used to retrieve values for |
| 45 | +// placeholders with keys that have a prefix of "body", "headers", or "files". |
| 46 | +// - headers (http.Header): The HTTP headers that may be used to retrieve |
| 47 | +// values for placeholders with keys that have a prefix of "headers". |
| 48 | +// - changedFiles (map[string]interface{}): A map of changed files that may be |
| 49 | +// used to retrieve values for placeholders with keys that have a prefix of |
| 50 | +// "files". |
25 | 51 | func ReplacePlaceHoldersVariables(template string, dico map[string]string, rawEvent any, headers http.Header, changedFiles map[string]interface{}) string { |
26 | 52 | return keys.ParamsRe.ReplaceAllStringFunc(template, func(s string) string { |
27 | 53 | parts := keys.ParamsRe.FindStringSubmatch(s) |
|
0 commit comments