common

package
v0.0.1-alpha8 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CelCompileAndEval

func CelCompileAndEval(ctx context.Context, scope *Scope, expr model.String, outPtr any) error

celCompileAndEval parses, compiles, and executes the given CEL expr with the given variables in scope.

The output of CEL execution is written into the location pointed to by outPtr. It must be a pointer. If the output of the CEL expression can't be converted to the given type, then an error will be returned. For example, if the CEL expression is "hello" and outPtr points to an int, an error will returned because CEL cannot treat "hello" as an integer.

func SortStrings

func SortStrings(in []string) []string

sortStrings sorts the given list of strings. Go's built-in sorting behavior modifies the string in place. It would be very weird if rendering a template changed the order of an input further down the stack.

func ToHyphenCase

func ToHyphenCase(v string) string

toHyphenCase converts a string to hyphen-case by removing all characters (except alphanumeric, hyphens, underscores and spaces) and replacing any hyphens or spaces with underscores.

func ToLowerHyphenCase

func ToLowerHyphenCase(v string) string

toLowerHyphenCase converts a string to hyphen-case by removing all characters (except alphanumeric, hyphens, underscores and spaces) and replacing any underscores or spaces with hyphens. The result is then returned as a lower case string.

func ToLowerSnakeCase

func ToLowerSnakeCase(v string) string

toLowerSnakeCase converts a string to snake_case by removing all characters (except alphanumeric, hyphens, underscores and spaces) and replacing any hyphens or spaces with underscores. The result is then returned as a lower case string.

func ToSnakeCase

func ToSnakeCase(v string) string

toSnakeCase converts a string to snake_case by removing all characters (except alphanumeric, hyphens, underscores and spaces) and replacing any hyphens or spaces with underscores.

func ToUpperHyphenCase

func ToUpperHyphenCase(v string) string

toUpperSnakeCase converts a string to hyphen-case by removing all characters (except alphanumeric, hyphens, underscores and spaces) and replacing any underscores or spaces with hyphens. The result is then returned as a upper case string.

func ToUpperSnakeCase

func ToUpperSnakeCase(v string) string

toUpperSnakeCase converts a string to snake_case by removing all characters (except alphanumeric, hyphens, underscores and spaces) and replacing any hyphens or spaces with underscores. The result is then returned as a upper case string.

Types

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

scope binds variable names to values. It has a stack-like structure that allows inner scopes to inherit values from outer scopes. Variable names are looked up in order of innermost-to-outermost.

For example, a for_each action defines a key value that is assigned to each of a list of values. The new variable introduced in this way "shadows" any variable that may previously exist of the same name. When the for_each loop is finished, then the outer scope's variable becomes available again.

func NewScope

func NewScope(m map[string]string) *Scope

func (*Scope) All

func (s *Scope) All() map[string]string

All returns all variable bindings that are in scope. Inner/top-of-stack bindings take priority over outer bindings of the same name.

The returned map is a copy that is owned by the caller; it can be changed safely.

The return value is never nil.

func (*Scope) Lookup

func (s *Scope) Lookup(name string) (string, bool)

Lookup returns the current value of a given variable name, or false.

func (*Scope) With

func (s *Scope) With(m map[string]string) *Scope

With returns a new scope containing a new set of variable values. It forwards lookups to the previously existing scope if the lookup key is not found in m.

Jump to

Keyboard shortcuts

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