content

package
v0.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetVariableIdentifierRegex

func SetVariableIdentifierRegex(r *regexp.Regexp)

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 Processed

type Processed map[string][]byte

Processed is a type alias for a map that maps strings to slices of bytes.

func (*Processed) Len

func (c *Processed) Len() int

Len returns the number of elements in the Processed map.

type Raw

type Raw []byte

Raw is a type alias for a byte slice used to represent raw policy content.

func (*Raw) ExtractVariables

func (c *Raw) ExtractVariables() []string

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

func (c *Raw) ReplaceVariables(vs map[string]string, f string) error

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"

func (*Raw) String

func (c *Raw) String() string

String returns the string representation of the Raw. Example usage:

c := Raw([]byte{'h', 'e', 'l', 'l', 'o'})
sourceRoot := c.String()  // sourceRoot = "hello"

type Source

type Source map[string]Raw

Source is a type alias for a map that associates string keys with values of type Raw.

func (*Source) Len

func (c *Source) Len() int

Len returns the length of the Source map.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL