Documentation ¶
Overview ¶
Package transforms provides a mechanism to define and apply string data transformations, with the transformations defined by regular expressions to match data to be transformed, and regular expression generators to specify additional or replacement data.
Index ¶
Constants ¶
const (
SCOPE_ANY = ""
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ScopedSpecNames ¶
ScopedSpecNames groups a list of Specs, referenced by their Spec name, with the group defined by a scope. The meaning of scope depends on the context in which the transforms are to be used.
For example, in the context of DNS request transforms, the scope is the DNS server for which a specific group of transforms is known to be effective.
The scope name "" is SCOPE_ANY, and matches any input scope name when there is no specific entry for that scope name in ScopedSpecNames.
func (ScopedSpecNames) Validate ¶
func (scopedSpecs ScopedSpecNames) Validate(specs Specs) error
Validate checks that the ScopedSpecNames is well-formed and referenced Spec names are defined in the corresponding input specs.
type Spec ¶
type Spec [][2]string
Spec is a transform spec. A spec is a list of individual transforms to be applied in order. Each transform is defined by two elements: a regular expression to by matched against the input; and a regular expression generator which generates new data. Subgroups from the regular expression may be specified in the regular expression generator, and are populated with the subgroup match, and in this way parts of the original matching data may be retained in the transformed data.
For example, with the transform [2]string{"([a-b])", "\\$\\ {1\\}"c}, substrings consisting of the characters 'a' and 'b' will be transformed into the same substring with a single character 'c' appended.
type Specs ¶
Specs is a set of named Specs.
func (Specs) Select ¶
func (specs Specs) Select(scope string, scopedSpecs ScopedSpecNames) (string, Spec)
Select picks a Spec from Specs based on the input scope and scoping rules. If the input scope name is defined in scopedSpecs, that match takes precedence. Otherwise SCOPE_ANY is selected, when present.
After the scope is resolved, Select randomly selects from the matching Spec list.
Select will return "", nil when no selection can be made.