Documentation ¶
Index ¶
- Variables
- func JSExec(ctx *Ctx, src string, env map[string]interface{}) (interface{}, error)
- func JSON(x interface{}) string
- func JSONMarshal(x interface{}) ([]byte, error)
- func StringKeys(x interface{}) (interface{}, error)
- type Bindings
- func (bs *Bindings) Bind(ctx *Ctx, x interface{}) (interface{}, error)
- func (bs *Bindings) Copy() (*Bindings, error)
- func (bs *Bindings) Set(value string) error
- func (bs *Bindings) SetJSON(key, value string) error
- func (bs *Bindings) SetValue(k string, v interface{})
- func (bs *Bindings) String() string
- func (bs *Bindings) UnmarshalBind(ctx *Ctx, js string) (string, error)
- type Ctx
- type Proc
- type Subber
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultDelimiters are the default opening and closing // deliminers for a pipe expression. DefaultDelimiters = "{}" // DefaultSerialization is the default serialization for a // pipe expression when the Subber doesn't think it knows // better. DefaultSerialization = "json" // DefaultLimit is the default limit for the number of // recursive substitution calls a Subber will make. // // If you hit this limit intentionally, then that's pretty // impressive. However, probably not something to brag about. DefaultLimit = 10 )
Functions ¶
func JSON ¶
func JSON(x interface{}) string
JSON attempts to serialize its input with a fallback to Go '%#v' serialization.
func JSONMarshal ¶ added in v0.7.7
JSONMarshal exists to SetEscapeHTML(false) to avoid messing with <, >, and &.
Strangely (to me), SetEscapeHTML(false) also seems to change newline treatment. See TestJSONMarshal's 'newline' test.
func StringKeys ¶
func StringKeys(x interface{}) (interface{}, error)
StringKeys will replace map[interface{}]interface{} with map[string]interface{} when that's possible and will return an error if not.
Types ¶
type Bindings ¶
type Bindings map[string]interface{}
Bindings maps variables to their values, which should probably all be native Go values.
func NewBindings ¶
func NewBindings() Bindings
func (*Bindings) Bind ¶
Bind replaces all structural variables in x with their corresponding values in bs (if any).
This operation is destructive (and probably shouldn't be).
An array or map should have interface{}-typed elements or values.
An unbound variable does not result in an error. See some comments in the Subber type.
func (*Bindings) Copy ¶
Copy bindings deeply.
This method shamelessly uses JSON serialization, which can break on certains types of values.
func (*Bindings) Set ¶
Set (for flag.Var) parses KEY=VALUE, where VALUE is a JSON representation of a value. Then key set to that value.
type Ctx ¶
Ctx mostly provides a list of directories a Subber will search to find files.
Instead of using a context.Context-like struct, we could have IncludeDirs as a field in a Subber. However, the current approach feels slightly more natural to use if still a little embarrassing.
type Proc ¶
Proc is a "processor" that a Subber can call.
A Proc computes an entire replacement for the given string.
Classic example is deserialization a JSON string input, doing structural replacement of bindings, and then reserializing. See Bindings.UnmarshalBind, which does exactly that.
type Subber ¶
type Subber struct { // Procs is a list of processors that are called during // (recursive) substitution processing. Procs []Proc // Limit is the maximum number of recursive Sub calls. // // Default is DefaultLimit. Limit int // DefaultSerialization is the serialization when an explicit // serialization isn't provided and the Subber doesn't think // it knows better (via scruffy heuristics). DefaultSerialization string // contains filtered or unexported fields }
Subber performs string-oriented substitutions based on a syntax like {VAR | PROC | SERIALIZATION}.
func NewSubber ¶
NewSubber makes a new Subber with the pipe expression delimiters given by the first and second runes of the given string.
Uses DefaultDelimiters by default.
Uses DefaultSerialization and DefaultLimit.