replvar

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: MIT Imports: 8 Imported by: 0

README

GoDoc

replvar

Variable replacement thingie

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Replace

func Replace(ctx context.Context, s string, mode string) (string, error)

Replace will replace any variable found in s with their value from the context

func Resolve deprecated added in v0.1.0

func Resolve(ctx context.Context, v string) any

Resolve returns the value for a variable name based on the context

Deprecated: use ParseVariable and resolve instead

func ResolveString deprecated added in v0.1.0

func ResolveString(ctx context.Context, v string) string

ResolveString returns the string value for a variable name based on the context

Deprecated: use ParseVariable and resolve instead

Types

type Token added in v0.1.0

type Token int
const (
	TokenInvalid Token = iota
	TokenVariable
	TokenNumber
	TokenStringConstant
	TokenVariableEnd // }}

	// operators
	TokenDot        // .
	TokenAdd        // +
	TokenSubstract  // -
	TokenMultiply   // *
	TokenDivide     // /
	TokenEqual      // ==
	TokenDifferent  // !=
	TokenNot        // !
	TokenOr         // |
	TokenBooleanOr  // ||
	TokenAnd        // &
	TokenBooleanAnd // &&
)

func (Token) MathOp added in v0.1.0

func (t Token) MathOp() string

type Var added in v0.1.0

type Var interface {
	Resolve(context.Context) (any, error) // resolve this variable and return its value
	IsStatic() bool                       // if true, it means this var will not change no matter what
}

Var is a resolvable variable

func ParseString added in v0.1.0

func ParseString(s string, mode string) (Var, error)

ParseString parses a constant string

func ParseVariable added in v0.1.0

func ParseVariable(s string) (Var, error)

ParseVariable parses a variable string, such as what is typically found inside {{}}

Jump to

Keyboard shortcuts

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