MCPcopy
hub / github.com/caddyserver/caddy / celMatcherStringListMacroExpander

Function celMatcherStringListMacroExpander

modules/caddyhttp/celmatcher.go:592–607  ·  view source on GitHub ↗

celMatcherStringListMacroExpander validates that the macro is called with a variable number of string arguments (at least one). The arguments are collected into a single list argument the following function call returned: <funcName>(request, [args])

(funcName string)

Source from the content-addressed store, hash-verified

590// The arguments are collected into a single list argument the following
591// function call returned: <funcName>(request, [args])
592func celMatcherStringListMacroExpander(funcName string) cel.MacroFactory {
593 return func(eh cel.MacroExprFactory, target ast.Expr, args []ast.Expr) (ast.Expr, *common.Error) {
594 matchArgs := []ast.Expr{}
595 if len(args) == 0 {
596 return nil, eh.NewError(0, "matcher requires at least one argument")
597 }
598 for _, arg := range args {
599 if isCELStringExpr(arg) {
600 matchArgs = append(matchArgs, arg)
601 } else {
602 return nil, eh.NewError(arg.ID(), "matcher arguments must be string constants")
603 }
604 }
605 return eh.NewCall(funcName, eh.NewIdent(CELRequestVarName), eh.NewList(matchArgs...)), nil
606 }
607}
608
609// celMatcherStringMacroExpander validates that the macro is called a single
610// string argument.

Callers 1

CELMatcherImplFunction · 0.85

Calls 2

IDMethod · 0.80
isCELStringExprFunction · 0.70

Tested by

no test coverage detected