el

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package el provides an interface and default implementation of expression language (EL) interpreter for struct tags.

Default implementation is simply based on "text/template".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	// Name of the currently processed field.
	Name string
	// Name of the currently processed field including type.
	LongName string
	// Current value of the currently processed filed.
	Val interface{}
	// All other tags of the currently processed field.
	Tags map[string]string
	// Currently processed struct.
	Struct interface{}
	// Extra context structure.
	Extra interface{}
	// Temporary partial result evaluated on the current substruct.
	Sub interface{}
}

Context is a context, passed to interpreter. It contains information about currently processed field, struct and extra.

type DefaultInterpreter

type DefaultInterpreter struct {
	// Custom functions, available for use in EL expressions.
	Funcs use.FuncMap
	// Left delimiter for templates.
	LeftDelim string
	// Right delimiter for templates.
	RightDelim string
	// Automatically enclose passed expression into delimiters before
	// interpretation (if it is not already enclosed). This allows to pass
	// simplified expressions. For example, `atoi "42"` instead of
	// `{{atoi "42"}}`.
	AutoEnclose bool
}

DefaultInterpreter is a default implementation of Interpreter, which is based on "text/template".

func (*DefaultInterpreter) Execute

func (i *DefaultInterpreter) Execute(
	expression string,
	ctx *Context) (interface{}, error)

Execute implements Interpreter.Execute()

type Interpreter

type Interpreter interface {
	// Execute parses and executes expression with a given context.
	Execute(expression string, ctx *Context) (result interface{}, err error)
}

Interpreter is an interface of EL interpreter.

Jump to

Keyboard shortcuts

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