el

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: CC0-1.0 Imports: 5 Imported by: 3 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func Assign(root interface{}, path string, want interface{}) (n int)

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

func Bool(expr string, root interface{}) (result bool, ok bool)

Bool returns the evaluation result if, and only if, the result has one value and the value is a boolean type.

func Bools

func Bools(expr string, root interface{}) []bool

Bools returns the evaluation result values of 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

func Float(expr string, root interface{}) (result float64, ok bool)

Float returns the evaluation result if, and only if, the result has one value and the value is a floating point type.

func Floats

func Floats(expr string, root interface{}) []float64

Floats returns the evaluation result values of a floating point type.

func Int

func Int(expr string, root interface{}) (result int64, ok bool)

Int returns the evaluation result if, and only if, the result has one value and the value is an integer type.

func Ints

func Ints(expr string, root interface{}) []int64

Ints returns the evaluation result values of an integer type.

func String

func String(expr string, root interface{}) (result string, ok bool)

String returns the evaluation result if, and only if, the result has one value and the value is a string type.

func Strings

func Strings(expr string, root interface{}) []string

Strings returns the evaluation result values of a string type.

func Uint

func Uint(expr string, root interface{}) (result uint64, ok bool)

Uint returns the evaluation result if, and only if, the result has one value and the value is an unsigned integer type.

func Uints

func Uints(expr string, root interface{}) []uint64

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.

Jump to

Keyboard shortcuts

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