Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetVariableIdentifierRegex ¶
SetVariableIdentifierRegex uses the given regex to update the - variableRegEx which is used to find and extract variable names from content. - variableReplaceFormat which is used to replace variable identifiers with a concrete value.
func SetVariableIdentifierRegexFromString ¶
func SetVariableIdentifierRegexFromString(s string)
SetVariableIdentifierRegexFromString creates a regex from the given string and updates the - variableRegEx which is used to find and extract variable names from content - variableReplaceFormat which is used to replace variable identifiers with a concrete value
Example:
SetVariableIdentifierRegexFromString("{Settings:(.+)}")
Types ¶
type Raw ¶
type Raw []byte
Raw is a type alias for a byte slice used to represent raw policy content.
func (*Raw) ExtractVariables ¶
ExtractVariables extracts unique variables from the Raw.
It uses a regular expression to find all matches of variables in the Raw. The found variables are stored in a slice without duplication.
Returns: - cm: a slice containing all unique variables found in the Raw.
func (*Raw) ReplaceVariables ¶
ReplaceVariables replaces variables in the Raw with provided values. It takes a map of variable-value pairs as input. If a variable is not found in the map, it returns an error. If the provided value for a variable is empty or equal to "null", it returns an error. This method uses regular expressions to find and replace variables in the Raw. It modifies the Raw in-place.
Example usage:
c := Raw("{Settings:foo}") vs := map[string]string{"foo": "bar"} err := c.ReplaceVariables(vs) if err != nil { fmt.Println(err) } sourceRoot := c.String() // sourceRoot = "bar"