Write expressions only in GOL fields that take CEL. The variables depend on the field: an object expression sees self, a policy sees subject, resource and context, and an action or Function sees its declared parameters. A variable from one kind of field is missing in another.
Functions and macros
| Family | Names | Use |
|---|---|---|
| Presence | has(value.field) | Check an optional field before you read it |
| Size | size(value), value.size() | Count a list, map or string |
| Conversion | string, int, double, bool | Convert a value; input that can't convert fails evaluation |
| Time | timestamp, duration, date | Parse a string into a time value |
| String predicates | contains, startsWith, endsWith, matches | Test text against a substring or a pattern |
| Collection macros | exists, all, exists_one | Test a condition over the members |
| Collection transforms | map, filter | Build a new list from the members |
| Gluon helpers | gluon.today, gluon.now, gluon.days, gluon.clamp, gluon.iban.valid, gluon.money | Each has its own page in this section |
date() passes the type checker but fails at runtime, because the runtime has no date() function. Use timestamp() or gluon.today() for now.
Operators
Arithmetic uses +, -, *, / and % on compatible types. Comparisons use ==, !=, <, <=, > and >=, and in tests membership. Conditions combine with !, && and ||, and condition ? yes : no picks a value. Field and index access must match the declared type. Subtracting two timestamps gives a duration.
Guard missing values
has(self.owner) && self.owner != ""
Guard every optional property with has(). The checker warns about an unguarded comparison with GLN-W206. In a policy, a condition over a missing value is unknown: an allow with that condition does not match, and a deny with it does.
Test the edges
Pin the clock with context.now in every time-dependent Test case. Add cases for an absent field, an empty list, input of the wrong type and a reader who is refused. An expression may run to 2,000 characters and a syntax-tree depth of 160, and it cannot reach the network.
