Documentation
¶
Overview ¶
Package el implements expression language "GoEL".
The API is error-free by design. Malformed expressions simply have no result.
Slash-separated paths specify content for lookups or modification. All paths are subjected to normalization rules. See http://golang.org/pkg/path#Clean
path ::= path-component | path path-component path-component ::= "/" segment segment ::= "" | ".." | selection | selection key selection ::= "." | go-field-name key ::= "[" key-selection "]" key-selection ::= "*" | go-literal
Both exported and non-exported struct fields can be selected by name.
Elements in indexed types array, slice and string are denoted with a zero based number inbetween square brackets. Key selections from map types also use the square bracket notation. Asterisk is treated as a wildcard.
Index ¶
- func Any(expr string, root interface{}) []interface{}
- func Assign(root interface{}, path string, want interface{}) (n int)
- func Bool(expr string, root interface{}) (result bool, ok bool)
- func Bools(expr string, root interface{}) []bool
- func Complex(expr string, root interface{}) (result complex128, ok bool)
- func Complexes(expr string, root interface{}) []complex128
- func Float(expr string, root interface{}) (result float64, ok bool)
- func Floats(expr string, root interface{}) []float64
- func Int(expr string, root interface{}) (result int64, ok bool)
- func Ints(expr string, root interface{}) []int64
- func String(expr string, root interface{}) (result string, ok bool)
- func Strings(expr string, root interface{}) []string
- func Uint(expr string, root interface{}) (result uint64, ok bool)
- func Uints(expr string, root interface{}) []uint64
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Any ¶
func Any(expr string, root interface{}) []interface{}
Any returns the evaluation result values.
func Assign ¶
Assign applies want to the path on root and returns the number of successes.
All content in the path is instantiated the fly with the zero value where possible. This implies automatic construction of structs, pointers and maps.
For the operation to succeed the targets must be settable conform to the third law of reflection. In short, root should be a pointer and the destination should be exported. See http://blog.golang.org/laws-of-reflection#TOC_8%2E
Example (PathAllocation) ¶
package main
import (
"fmt"
"github.com/pascaldekloe/goe/el"
)
func main() {
type node struct {
Child *node
Label string
}
x := new(node)
el.Assign(x, "/Child/Child/Label", "Hello")
fmt.Printf("%v", x.Child.Child)
}
Output: &{<nil> Hello}
Example (TypeFlexibility) ¶
package main
import (
"fmt"
"github.com/pascaldekloe/goe/el"
)
func main() {
type numbers struct {
B byte
I uint32
F float64
}
x := new(numbers)
el.Assign(x, "/*", 42)
fmt.Printf("%+v", x)
}
Output: &{B:42 I:42 F:42}
func Bool ¶
Bool returns the evaluation result if, and only if, the result has one value and the value is a boolean type.
func Complex ¶
func Complex(expr string, root interface{}) (result complex128, ok bool)
Complex returns the evaluation result if, and only if, the result has one value and the value is a complex type.
func Complexes ¶
func Complexes(expr string, root interface{}) []complex128
Complexes returns the evaluation result values of a complex type.
func Float ¶
Float returns the evaluation result if, and only if, the result has one value and the value is a floating point type.
func Int ¶
Int returns the evaluation result if, and only if, the result has one value and the value is an integer type.
func String ¶
String returns the evaluation result if, and only if, the result has one value and the value is a string type.
func Uint ¶
Uint returns the evaluation result if, and only if, the result has one value and the value is an unsigned integer type.
func Uints ¶
Uints returns the evaluation result values of an unsigned integer type.
Example ¶
package main
import (
"fmt"
"image/gif"
"strings"
"github.com/pascaldekloe/goe/el"
)
func main() {
data := "\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x80\x00\x00\xff\xff\xff\x00\x00\x00\x2c\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02\x44\x01\x00\x3b"
img, err := gif.Decode(strings.NewReader(data))
if err != nil {
panic(err)
}
fmt.Printf("RGBA: %v", el.Uints("/Palette[0]/*", img))
}
Output: RGBA: [255 255 255 255]
Types ¶
This section is empty.