Documentation ¶
Index ¶
- func CompileAnyExpression(s string) (*vm.Program, error)
- func CompileBoolExpression(s string) (*vm.Program, error)
- func CompileStringExpression(s string) (*vm.Program, error)
- func ResolveBoolExpression(vm *vm.Program, ctx Context) (bool, error)
- func ResolveStringExpression(vm *vm.Program, ctx Context) (string, error)
- type Context
- type Request
- type RequestAuth
- type RequestHeaders
- type RequestURL
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompileBoolExpression ¶
CompileBoolExpression compiles an expression and returns the program. It is used for expressions that return bool. The exprContext is used to provide the context for the expression evaluation. Not safe for concurrent use.
func CompileStringExpression ¶
CompileStringExpression compiles an expression and returns the program. It is used for expressions that return strings The exprContext is used to provide the context for the expression evaluation. Not safe for concurrent use.
func ResolveBoolExpression ¶
ResolveBoolExpression evaluates the expression and returns the result as a bool. The exprContext is used to provide the context for the expression evaluation. Not safe for concurrent use.
Types ¶
type Context ¶
type Context struct {
Request Request `expr:"request"`
}
Context is the context for expressions parser when evaluating dynamic expressions
type Request ¶
type Request struct { Auth RequestAuth `expr:"auth"` URL RequestURL `expr:"url"` Header RequestHeaders `expr:"header"` }
Request is the context for the request object in expressions. Be aware, that only value receiver methods are exported in the expr environment. This is because the expressions are evaluated in a read-only context.
func LoadRequest ¶
LoadRequest loads the request object into the context.
type RequestAuth ¶
type RequestAuth struct { IsAuthenticated bool `expr:"isAuthenticated"` Type string `expr:"type"` Claims map[string]any `expr:"claims"` Scopes []string `expr:"scopes"` }
func LoadAuth ¶
func LoadAuth(ctx context.Context) RequestAuth
LoadAuth loads the authentication context into the request object. Must only be called when the authentication was successful.
type RequestHeaders ¶
func (RequestHeaders) Get ¶
func (r RequestHeaders) Get(key string) string
Get returns the value of the header with the given key. If the header is not present, an empty string is returned. The key is case-insensitive and transformed to the canonical format. TODO: Use interface to expose only the required methods. Blocked by https://github.com/expr-lang/expr/issues/744
type RequestURL ¶
type RequestURL struct { Method string `expr:"method"` // Scheme is the scheme of the URL Scheme string `expr:"scheme"` // Host is the host of the URL Host string `expr:"host"` // Path is the path of the URL Path string `expr:"path"` // Query is the parsed query parameters Query map[string]string `expr:"query"` }
RequestURL is the context for the URL object in expressions it is limited in scope to the URL object and its components. For convenience, the query parameters are parsed.