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 Body
- type Client
- type ClientTrace
- type Context
- type Manager
- type Operation
- type Request
- type RequestAuth
- type RequestHeaders
- type RequestURL
- type Response
- type Subgraph
- type SubgraphRequest
- type SubgraphResponse
- type Trace
- type UsesBody
- type UsesResponseBody
- type UsesSubgraph
- type UsesSubgraphResponseBody
- type UsesSubgraphTrace
- type VisitorGroup
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 ClientTrace ¶
type ClientTrace struct {
ConnectionAcquireDuration float64 `expr:"connAcquireDuration"`
}
type Context ¶
type Context struct { Request Request `expr:"request"` // if changing the expr tag, the ExprRequestKey should be updated Response Response `expr:"response"` Subgraph Subgraph `expr:"subgraph"` }
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 Body `expr:"body"` Trace Trace `expr:"trace"` Operation Operation `expr:"operation"` Client Client `expr:"client"` Error error `expr:"error"` }
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.
type Subgraph ¶
type Subgraph struct { Id string `expr:"id"` Name string `expr:"name"` Request SubgraphRequest `expr:"request"` Response SubgraphResponse `expr:"response"` }
Subgraph Related
type SubgraphRequest ¶
type SubgraphRequest struct { Error error `expr:"error"` ClientTrace ClientTrace `expr:"clientTrace"` }
type SubgraphResponse ¶
type SubgraphResponse struct {
Body Body `expr:"body"`
}
type UsesResponseBody ¶
type UsesResponseBody struct {
UsesResponseBody bool
}
This visitor is used to identify if expressions use response.body
func (*UsesResponseBody) Visit ¶
func (v *UsesResponseBody) Visit(baseNode *ast.Node)
type UsesSubgraph ¶
type UsesSubgraph struct {
UsesSubgraph bool
}
This visitor is used to identify if expressions should be executed in a subgraph context
func (*UsesSubgraph) Visit ¶
func (v *UsesSubgraph) Visit(baseNode *ast.Node)
type UsesSubgraphResponseBody ¶
type UsesSubgraphResponseBody struct {
UsesSubgraphResponseBody bool
}
This visitor is used to identify if expressions use subgraph.response.body
func (*UsesSubgraphResponseBody) Visit ¶
func (v *UsesSubgraphResponseBody) Visit(baseNode *ast.Node)
type UsesSubgraphTrace ¶
type UsesSubgraphTrace struct {
UsesSubgraphTrace bool
}
This visitor is used to identify if we should enable client tracing because clientTrace has been accessed in an expression
func (*UsesSubgraphTrace) Visit ¶
func (v *UsesSubgraphTrace) Visit(baseNode *ast.Node)
type VisitorGroup ¶
type VisitorGroup struct {
// contains filtered or unexported fields
}
VisitorGroup is a struct that holds all the VisitorManager that are used to compile the expressions We use a separate struct so that the visitor is passed in to places will use it that are in the request chain this means that they don't have access to compiling expressions in a request by default via the expr manager
func (*VisitorGroup) IsRequestBodyUsedInExpressions ¶
func (c *VisitorGroup) IsRequestBodyUsedInExpressions() bool
func (*VisitorGroup) IsResponseBodyUsedInExpressions ¶
func (c *VisitorGroup) IsResponseBodyUsedInExpressions() bool
func (*VisitorGroup) IsSubgraphResponseBodyUsedInExpressions ¶
func (c *VisitorGroup) IsSubgraphResponseBodyUsedInExpressions() bool
func (*VisitorGroup) IsSubgraphTraceUsedInExpressions ¶
func (c *VisitorGroup) IsSubgraphTraceUsedInExpressions() bool