Documentation ¶
Overview ¶
shared interfaces and utility functions
Index ¶
- Constants
- Variables
- func ContainsComparison(left, right interface{}) bool
- func EqualsComparison(left, right interface{}) bool
- func GreaterThanComparison(left, right interface{}) bool
- func GreaterThanOrEqualComparison(left, right interface{}) bool
- func IsTokenEnd(b byte) bool
- func LessThanComparison(left, right interface{}) bool
- func LessThanOrEqualComparison(left, right interface{}) bool
- func NotContainsComparison(left, right interface{}) bool
- func NotEqualsComparison(left, right interface{}) bool
- func NotUnaryComparison(left, right interface{}) bool
- func RegisterFilter(name string, factory FilterFactory)
- func Resolve(data interface{}, field string) interface{}
- func ResolveFinal(value interface{}) interface{}
- func SkipSpaces(data []byte) int
- func ToBytes(data interface{}) []byte
- func ToInt(data interface{}) (int, bool)
- func ToLength(input interface{}) (int, bool)
- func ToString(data interface{}) string
- func TrimStrings(values []string) []string
- func UnaryComparison(left, right interface{}) bool
- type Cache
- type Code
- type ComparisonOperator
- type Completable
- type Condition
- type ConditionGroup
- type ConditionResolver
- type Configuration
- func (c *Configuration) Cache(cache Cache) *Configuration
- func (c *Configuration) GetCache() Cache
- func (c *Configuration) GetIncludeHandler() IncludeHandler
- func (c *Configuration) GetPreserveWhitespace() bool
- func (c *Configuration) IncludeHandler(handler IncludeHandler) *Configuration
- func (c *Configuration) PreserveWhitespace() *Configuration
- type DynamicValue
- type ExecuteState
- type Filter
- type FilterFactory
- type IncludeHandler
- type LogicalOperator
- type MarkupType
- type Parser
- func (p *Parser) Current() byte
- func (p *Parser) Error(s string) error
- func (p *Parser) Forward()
- func (p *Parser) ForwardBy(count int)
- func (p *Parser) HasMore() bool
- func (p *Parser) Left() int
- func (p *Parser) Out()
- func (p *Parser) Peek() byte
- func (p *Parser) ReadComparisonOperator() ComparisonOperator
- func (p *Parser) ReadConditionGroup() (Verifiable, error)
- func (p *Parser) ReadDynamicValues() (Value, error)
- func (p *Parser) ReadFilters() ([]Filter, error)
- func (p *Parser) ReadLogicalOperator() LogicalOperator
- func (p *Parser) ReadName() string
- func (p *Parser) ReadParameters() ([]Value, error)
- func (p *Parser) ReadPartialCondition() (Completable, error)
- func (p *Parser) ReadRangeValue() (Value, error)
- func (p *Parser) ReadStaticBoolValue() (Value, bool)
- func (p *Parser) ReadStaticEmptyValue() (Value, bool)
- func (p *Parser) ReadStaticNumericValue() (Value, error)
- func (p *Parser) ReadStaticStringValue(delimiter byte) (Value, error)
- func (p *Parser) ReadValue() (Value, error)
- func (p *Parser) SkipPastOutput()
- func (p *Parser) SkipPastTag()
- func (p *Parser) SkipSpaces() (current byte)
- func (p *Parser) SkipUntil(b byte) (current byte)
- func (p *Parser) Snapshot(start int) []byte
- func (p *Parser) ToMarkup(preserveWhitespace bool) ([]byte, MarkupType)
- type RangeValue
- type StaticBoolValue
- type StaticEmptyValue
- type StaticFloatValue
- type StaticIntValue
- type StaticStringValue
- type Tag
- type TagType
- type TrueCondition
- type Type
- type Value
- type Verifiable
Constants ¶
const ( OR LogicalOperator = iota AND UnknownLogical Equals ComparisonOperator = iota NotEquals LessThan GreaterThan LessThanOrEqual GreaterThanOrEqual Contains NotContains Unary NotUnary UnknownComparator String Type = iota Nil Int Int64 Uint Float64 Complex128 Bool Time Today Array Unknown )
Variables ¶
var ( EmptyBytes = []byte{} Whitespace = []byte(" ") )
var BytePool = bytepool.New(128, 4096)
var ConditionLookup = map[ComparisonOperator]ConditionResolver{ Unary: UnaryComparison, NotUnary: NotUnaryComparison, Equals: EqualsComparison, NotEquals: NotEqualsComparison, LessThan: LessThanComparison, GreaterThan: GreaterThanComparison, LessThanOrEqual: LessThanOrEqualComparison, GreaterThanOrEqual: GreaterThanOrEqualComparison, Contains: ContainsComparison, }
var FilterLookup = make(map[string]FilterFactory)
A map of filter names to filter factories
var KindToType = map[reflect.Kind]Type{ reflect.String: String, reflect.Int: Int, reflect.Int64: Int64, reflect.Uint: Uint, reflect.Float64: Float64, reflect.Complex128: Complex128, reflect.Bool: Bool, reflect.Array: Array, reflect.Slice: Array, reflect.Map: Array, }
var (
Now = func() time.Time { return time.Now() }
)
var TypeOperations = map[Type]map[ComparisonOperator]ConditionResolver{ String: map[ComparisonOperator]ConditionResolver{ Equals: func(left, right interface{}) bool { return left.(string) == right.(string) }, LessThan: func(left, right interface{}) bool { return left.(string) < right.(string) }, }, Nil: map[ComparisonOperator]ConditionResolver{ Equals: func(left, right interface{}) bool { return left == nil && right == nil }, LessThan: func(left, right interface{}) bool { return false }, }, Int: map[ComparisonOperator]ConditionResolver{ Equals: func(left, right interface{}) bool { return left.(int) == right.(int) }, LessThan: func(left, right interface{}) bool { return left.(int) < right.(int) }, }, Int64: map[ComparisonOperator]ConditionResolver{ Equals: func(left, right interface{}) bool { return left.(int64) == right.(int64) }, LessThan: func(left, right interface{}) bool { return left.(int64) < right.(int64) }, }, Uint: map[ComparisonOperator]ConditionResolver{ Equals: func(left, right interface{}) bool { return left.(uint) == right.(uint) }, LessThan: func(left, right interface{}) bool { return left.(uint) < right.(uint) }, }, Float64: map[ComparisonOperator]ConditionResolver{ Equals: func(left, right interface{}) bool { return left.(float64) == right.(float64) }, LessThan: func(left, right interface{}) bool { return left.(float64) < right.(float64) }, }, Complex128: map[ComparisonOperator]ConditionResolver{ Equals: func(left, right interface{}) bool { return left.(complex128) == right.(complex128) }, LessThan: func(left, right interface{}) bool { return false }, }, Bool: map[ComparisonOperator]ConditionResolver{ Equals: func(left, right interface{}) bool { return left.(bool) == right.(bool) }, LessThan: func(left, right interface{}) bool { return false }, }, Time: map[ComparisonOperator]ConditionResolver{ Equals: func(left, right interface{}) bool { return left.(time.Time).Unix() == right.(time.Time).Unix() }, LessThan: func(left, right interface{}) bool { return left.(time.Time).Unix() < right.(time.Time).Unix() }, }, Today: map[ComparisonOperator]ConditionResolver{ Equals: func(left, right interface{}) bool { l, r := left.(time.Time), right.(time.Time) return l.YearDay() == r.YearDay() && l.Year() == r.Year() }, LessThan: func(left, right interface{}) bool { l, r := left.(time.Time), right.(time.Time) if l.Year() > r.Year() { return false } if l.Year() < r.Year() { return true } return l.YearDay() < r.YearDay() }, }, Array: map[ComparisonOperator]ConditionResolver{ Equals: func(left, right interface{}) bool { return reflect.DeepEqual(left, right) }, LessThan: func(left, right interface{}) bool { return reflect.ValueOf(left).Len() < reflect.ValueOf(right).Len() }, }, }
Functions ¶
func ContainsComparison ¶
func ContainsComparison(left, right interface{}) bool
I think most of this sucks
func EqualsComparison ¶
func EqualsComparison(left, right interface{}) bool
func GreaterThanComparison ¶
func GreaterThanComparison(left, right interface{}) bool
func GreaterThanOrEqualComparison ¶
func GreaterThanOrEqualComparison(left, right interface{}) bool
func IsTokenEnd ¶
func LessThanComparison ¶
func LessThanComparison(left, right interface{}) bool
func LessThanOrEqualComparison ¶
func LessThanOrEqualComparison(left, right interface{}) bool
func NotContainsComparison ¶
func NotContainsComparison(left, right interface{}) bool
func NotEqualsComparison ¶
func NotEqualsComparison(left, right interface{}) bool
func NotUnaryComparison ¶
func NotUnaryComparison(left, right interface{}) bool
func RegisterFilter ¶
func RegisterFilter(name string, factory FilterFactory)
Register's a filter for the given name (not thread-safe)
func Resolve ¶
func Resolve(data interface{}, field string) interface{}
Resolves the value of field within data
func ResolveFinal ¶
func ResolveFinal(value interface{}) interface{}
This is necessary in the case where the value references a struct directly:
template := "{{ user }}"" data := map[string]interface{}{"user": &User{"Leto"}},
Without this step, the above would result in a value which points to the User we need to resolve this a step further and get the value of "User" (which will either me the output of its String() method, or %v)
Of course, we only want this final resolution once we need the value. If we call this too early, say in Resolve above, we won't be able to build nested paths
func SkipSpaces ¶
return the position of the first none space, or -1 if no white space exists
func TrimStrings ¶
Since these templates are possibly long-lived, let's free up any space which was accumulated while we grew these arrays
func UnaryComparison ¶
func UnaryComparison(left, right interface{}) bool
Types ¶
type Code ¶
type Code interface {
Execute(writer io.Writer, data map[string]interface{}) ExecuteState
}
interface for something that can render itself
type ComparisonOperator ¶
type ComparisonOperator int
type Completable ¶
type Completable interface { Complete(value Value, operator ComparisonOperator) Verifiable }
type Condition ¶
type Condition struct {
// contains filtered or unexported fields
}
represents a conditions (such as x == y)
type ConditionGroup ¶
type ConditionGroup struct {
// contains filtered or unexported fields
}
represents a group of conditions
func (ConditionGroup) Complete ¶
func (g ConditionGroup) Complete(value Value, operator ComparisonOperator)
func (*ConditionGroup) Inverse ¶
func (g *ConditionGroup) Inverse()
func (*ConditionGroup) IsTrue ¶
func (g *ConditionGroup) IsTrue(data map[string]interface{}) bool
type ConditionResolver ¶
type ConditionResolver func(left, right interface{}) bool
Resolves a condition
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration used for generating a template
func (*Configuration) Cache ¶
func (c *Configuration) Cache(cache Cache) *Configuration
Set the caching engine, or nil for no caching
func (*Configuration) GetIncludeHandler ¶
func (c *Configuration) GetIncludeHandler() IncludeHandler
Gets the configured include handler
func (*Configuration) GetPreserveWhitespace ¶
func (c *Configuration) GetPreserveWhitespace() bool
Gets the preserves whitespace value
func (*Configuration) IncludeHandler ¶
func (c *Configuration) IncludeHandler(handler IncludeHandler) *Configuration
Set the include handler
func (*Configuration) PreserveWhitespace ¶
func (c *Configuration) PreserveWhitespace() *Configuration
Preserves whitespace
type DynamicValue ¶
type DynamicValue struct { Fields []string // contains filtered or unexported fields }
func NewDynamicValue ¶
func NewDynamicValue(fields []string) *DynamicValue
func (*DynamicValue) Resolve ¶
func (v *DynamicValue) Resolve(data map[string]interface{}) interface{}
func (*DynamicValue) ResolveWithNil ¶
func (v *DynamicValue) ResolveWithNil(data map[string]interface{}) interface{}
func (*DynamicValue) Underlying ¶
func (v *DynamicValue) Underlying() interface{}
type Filter ¶
type Filter func(input interface{}, data map[string]interface{}) interface{}
An interface function
type FilterFactory ¶
A filter factory creates a filter based on the supplied parameters
type IncludeHandler ¶
The callback to execute to resolve include tags If you're going to use name to read from the filesystem, beware of directory traversal.
type LogicalOperator ¶
type LogicalOperator int
type Parser ¶
func (*Parser) ReadComparisonOperator ¶
func (p *Parser) ReadComparisonOperator() ComparisonOperator
func (*Parser) ReadConditionGroup ¶
func (p *Parser) ReadConditionGroup() (Verifiable, error)
func (*Parser) ReadDynamicValues ¶
func (*Parser) ReadFilters ¶
func (*Parser) ReadLogicalOperator ¶
func (p *Parser) ReadLogicalOperator() LogicalOperator
func (*Parser) ReadParameters ¶
func (*Parser) ReadPartialCondition ¶
func (p *Parser) ReadPartialCondition() (Completable, error)
func (*Parser) ReadRangeValue ¶
func (*Parser) ReadStaticBoolValue ¶
func (*Parser) ReadStaticEmptyValue ¶
func (*Parser) ReadStaticNumericValue ¶
func (*Parser) ReadStaticStringValue ¶
func (*Parser) SkipPastOutput ¶
func (p *Parser) SkipPastOutput()
func (*Parser) SkipPastTag ¶
func (p *Parser) SkipPastTag()
func (*Parser) SkipSpaces ¶
type RangeValue ¶
type RangeValue struct {
// contains filtered or unexported fields
}
func (*RangeValue) Resolve ¶
func (v *RangeValue) Resolve(data map[string]interface{}) interface{}
func (*RangeValue) ResolveWithNil ¶
func (v *RangeValue) ResolveWithNil(data map[string]interface{}) interface{}
func (*RangeValue) Underlying ¶
func (v *RangeValue) Underlying() interface{}
type StaticBoolValue ¶
type StaticBoolValue struct {
Value bool
}
func (*StaticBoolValue) Resolve ¶
func (v *StaticBoolValue) Resolve(data map[string]interface{}) interface{}
func (*StaticBoolValue) ResolveWithNil ¶
func (v *StaticBoolValue) ResolveWithNil(data map[string]interface{}) interface{}
func (*StaticBoolValue) Underlying ¶
func (v *StaticBoolValue) Underlying() interface{}
type StaticEmptyValue ¶
type StaticEmptyValue struct{}
func (*StaticEmptyValue) Resolve ¶
func (v *StaticEmptyValue) Resolve(data map[string]interface{}) interface{}
func (*StaticEmptyValue) ResolveWithNil ¶
func (v *StaticEmptyValue) ResolveWithNil(data map[string]interface{}) interface{}
func (*StaticEmptyValue) Underlying ¶
func (v *StaticEmptyValue) Underlying() interface{}
type StaticFloatValue ¶
type StaticFloatValue struct {
Value float64
}
func (*StaticFloatValue) Resolve ¶
func (v *StaticFloatValue) Resolve(data map[string]interface{}) interface{}
func (*StaticFloatValue) ResolveWithNil ¶
func (v *StaticFloatValue) ResolveWithNil(data map[string]interface{}) interface{}
func (*StaticFloatValue) Underlying ¶
func (v *StaticFloatValue) Underlying() interface{}
type StaticIntValue ¶
type StaticIntValue struct {
Value int
}
func (*StaticIntValue) Resolve ¶
func (v *StaticIntValue) Resolve(data map[string]interface{}) interface{}
func (*StaticIntValue) ResolveWithNil ¶
func (v *StaticIntValue) ResolveWithNil(data map[string]interface{}) interface{}
func (*StaticIntValue) Underlying ¶
func (v *StaticIntValue) Underlying() interface{}
type StaticStringValue ¶
type StaticStringValue struct {
Value string
}
func (*StaticStringValue) Resolve ¶
func (v *StaticStringValue) Resolve(data map[string]interface{}) interface{}
func (*StaticStringValue) ResolveWithNil ¶
func (v *StaticStringValue) ResolveWithNil(data map[string]interface{}) interface{}
func (*StaticStringValue) Underlying ¶
func (v *StaticStringValue) Underlying() interface{}
type Tag ¶
type Tag interface { AddCode(code Code) AddSibling(tag Tag) error Name() string Type() TagType Code }
interface for an tag markup
type TrueCondition ¶
type TrueCondition struct {
// contains filtered or unexported fields
}
func (*TrueCondition) Inverse ¶
func (t *TrueCondition) Inverse()
func (*TrueCondition) IsTrue ¶
func (t *TrueCondition) IsTrue(data map[string]interface{}) bool
type Value ¶
type Value interface { Resolve(data map[string]interface{}) interface{} ResolveWithNil(data map[string]interface{}) interface{} Underlying() interface{} }
Represents a value, which can either be static or dynamic
func TrimValues ¶
Since these templates are possibly long-lived, let's free up any space which was accumulated while we grew these arrays