Documentation
¶
Index ¶
- Constants
- func ResolveAnyExpression(vm *vm.Program, ctx Context) (any, error)
- func ResolveBoolExpression(vm *vm.Program, ctx Context) (bool, error)
- func ResolveStringExpression(vm *vm.Program, ctx Context) (string, error)
- type Context
- type Manager
- type Request
- type RequestAuth
- type RequestBody
- type RequestHeaders
- type RequestURL
- type Trace
- type UsesBody
Constants ¶
const ExprRequestAuthKey = "auth"
const ExprRequestKey = "request"
Variables ¶
This section is empty.
Functions ¶
func ResolveAnyExpression ¶
ResolveAnyExpression evaluates the expression and returns the result as a any. 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"` // if changing the expr tag, the ExprRequestKey should be updated
}
Context is the context for expressions parser when evaluating dynamic expressions
type Manager ¶
type Manager struct {
VisitorManager *visitorGroup
}
func CreateNewExprManager ¶
func CreateNewExprManager() *Manager
func (*Manager) CompileAnyExpression ¶
func (c *Manager) CompileAnyExpression(exprString string, visitors ...ast.Visitor) (*vm.Program, error)
CompileAnyExpression compiles an expression and returns the program for any type. The exprContext is used to provide the context for the expression evaluation. Not safe for concurrent use.
func (*Manager) CompileExpression ¶
func (c *Manager) CompileExpression(exprString string, kind reflect.Kind, visitors ...ast.Visitor) (*vm.Program, error)
CompileExpression compiles an expression and returns the program for the specific type. The exprContext is used to provide the context for the expression evaluation. Not safe for concurrent use.
func (*Manager) ValidateAnyExpression ¶
ValidateAnyExpression compiles the expression to ensure that the expression itself is valid but more importantly it checks if the return type is not nil and is an allowed return type this allows us to ensure that nil and return types such as func or channels are not returned
type Request ¶
type Request struct { Auth RequestAuth `expr:"auth"` // if changing the expr tag, the ExprRequestAuthKey should be updated URL RequestURL `expr:"url"` Header RequestHeaders `expr:"header"` Body RequestBody `expr:"body"` Error error `expr:"error"` Trace Trace `expr:"trace"` }
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 RequestBody ¶
type RequestBody struct {
Raw string `expr:"raw"`
}
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.