func CELMatcherDecorator(funcName string, fac CELMatcherFactory) interpreter.InterpretableDecorator {
	return func(i interpreter.Interpretable) (interpreter.Interpretable, error) {
		call, ok := i.(interpreter.InterpretableCall)
		if !ok {
			return i, nil
		}
		if call.OverloadID() != funcName {
			return i, nil
		}
		callArgs := call.Args()
		reqAttr, ok := callArgs[0].(interpreter.InterpretableAttribute)
		if !ok {
			return nil, errors.New("missing 'request' argument")
		}
		nsAttr, ok := reqAttr.Attr().(interpreter.NamespacedAttribute)
		if !ok {
			return nil, errors.New("missing 'request' argument")
		}
		varNames := nsAttr.CandidateVariableNames()
		if len(varNames) != 1 || len(varNames) == 1 && varNames[0] != "request" {
			return nil, errors.New("missing 'request' argument")
		}
		matcherData, ok := callArgs[1].(interpreter.InterpretableConst)
		if !ok {
			// If the matcher arguments are not constant, then this means
			// they contain a Caddy placeholder reference and the evaluation
			// and matcher provisioning should be handled at dynamically.
			return i, nil
		}
		matcher, err := fac(matcherData.Value())
		if err != nil {
			return nil, err
		}
		return interpreter.NewCall(
			i.ID(), funcName, funcName+"_opt",
			[]interpreter.Interpretable{reqAttr},
			func(args ...ref.Val) ref.Val {
				// The request value, guaranteed to be of type celHTTPRequest
				celReq := args[0]
				// If needed this call could be changed to convert the value
				// to a *http.Request using CEL's ConvertToNative method.
				httpReq := celReq.Value().(celHTTPRequest)
				return types.Bool(matcher.Match(httpReq.Request))
			},
		), nil
	}
}
// CELMatcherDecorator matches a call overload generated by a CEL macro
// that takes a single argument, and optimizes the implementation to precompile
// the matcher and return a function that references the precompiled and
// provisioned matcher.
CELMatcherDecorator matches a call overload generated by a CEL macro
that takes a single argument, and optimizes the implementation to precompile
the matcher and return a function that references the precompiled and
provisioned matcher.
// CELMatcherDecorator matches a call overload generated by a CEL macro // that takes a single argument and optimizes the implementation to precompile // the matcher and return a function that references the precompiled and // provisioned matcher .
func CELMatcherDecorator(funcName string, fac CELMatcherFactory) interpreter.InterpretableDecorator {
	return func(i interpreter.Interpretable) (interpreter.Interpretable, error) {
		call, ok := i.(interpreter.InterpretableCall)
		if !ok {
			return i, nil
		}
		if call.OverloadID() != funcName {
			return i, nil
		}
		callArgs := call.Args()
		reqAttr, ok := callArgs[0].(interpreter.InterpretableAttribute)
		if !ok {
			return nil, errors.New("missing 'request' argument")
		}
		nsAttr, ok := reqAttr.Attr().(interpreter.NamespacedAttribute)
		if !ok {
			return nil, errors.New("missing 'request' argument")
		}
		varNames := nsAttr.CandidateVariableNames()
		if len(varNames) != 1 || len(varNames) == 1 && varNames[0] != "request" {
			return nil, errors.New("missing 'request' argument")
		}
		matcherData, ok := callArgs[1].(interpreter.InterpretableConst)
		if !ok {
			return i, nil
		}
		matcher, err := fac(matcherData.Value())
		if err != nil {
			return nil, err
		}
		return interpreter.NewCall(
			i.ID(), funcName, funcName+"_opt",
			[]interpreter.Interpretable{reqAttr},
			func(args ...ref.Val) ref.Val {
				celReq := args[0]
				httpReq := celReq.Value().(celHTTPRequest)
				return types.Bool(matcher.Match(httpReq.Request))
			},
		), nil
	}
}
func CELMatcherDecorator ( funcName string , fac CELMatcherFactory ) interpreter . InterpretableDecorator { return func ( i interpreter . Interpretable ) ( interpreter . Interpretable , error ) { call , ok := i . ( interpreter . InterpretableCall ) if ! ok { return i , nil } if call . OverloadID ( ) != funcName { return i , nil } callArgs := call . Args ( ) reqAttr , ok := callArgs [ 0 ] . ( interpreter . InterpretableAttribute ) if ! ok { return nil , errors . New ( " " ) } nsAttr , ok := reqAttr . Attr ( ) . ( interpreter . NamespacedAttribute ) if ! ok { return nil , errors . New ( " " ) } varNames := nsAttr . CandidateVariableNames ( ) if len ( varNames ) != 1 || len ( varNames ) == 1 && varNames [ 0 ] != " " { return nil , errors . New ( " " ) } matcherData , ok := callArgs [ 1 ] . ( interpreter . InterpretableConst ) if ! ok { return i , nil } matcher , err := fac ( matcherData . Value ( ) ) if err != nil { return nil , err } return interpreter . NewCall ( i . ID ( ) , funcName , funcName + " " , [ ] interpreter . Interpretable { reqAttr } , func ( args ... ref . Val ) ref . Val { celReq := args [ 0 ] httpReq := celReq . Value ( ) . ( celHTTPRequest ) return types . Bool ( matcher . Match ( httpReq . Request ) ) } , ) , nil } }
CELMatcherDecorator matches a call overload generated by a CEL macro
that takes a single argument, and optimizes the implementation to precompile
the matcher and return a function that references the precompiled and
provisioned matcher.
CELMatcherDecorator matches a call overload generated by a CEL macro that takes a single argument and optimizes the implementation to precompile the matcher and return a function that references the precompiled and provisioned matcher .
// If the matcher arguments are not constant, then this means // they contain a Caddy placeholder reference and the evaluation // and matcher provisioning should be handled at dynamically. // The request value, guaranteed to be of type celHTTPRequest // If needed this call could be changed to convert the value // to a *http.Request using CEL's ConvertToNative method.