MCPcopy Create free account
hub / github.com/kataras/iris / CanMakeHandler

Function CanMakeHandler

macro/handler/handler.go:33–58  ·  view source on GitHub ↗

alias. CanMakeHandler reports whether a macro template needs a special macro's evaluator handler to be validated before procceed to the next handler(s). If the template does not contain any dynamic attributes and a special handler is NOT required then it returns false.

(tmpl macro.Template)

Source from the content-addressed store, hash-verified

31// If the template does not contain any dynamic attributes and a special handler is NOT required
32// then it returns false.
33func CanMakeHandler(tmpl macro.Template) (needsMacroHandler bool) {
34 if len(tmpl.Params) == 0 {
35 return
36 }
37
38 // check if we have params like: {name:string} or {name} or {anything:path} without else keyword or any functions used inside these params.
39 // 1. if we don't have, then we don't need to add a handler before the main route's handler (as I said, no performance if macro is not really used)
40 // 2. if we don't have any named params then we don't need a handler too.
41 for i := range tmpl.Params {
42 p := tmpl.Params[i]
43 if p.CanEval() {
44 // if at least one needs it, then create the handler.
45 needsMacroHandler = true
46
47 if p.HandleError != nil {
48 // Check for its type.
49 if _, ok := p.HandleError.(ParamErrorHandler); !ok {
50 panic(fmt.Sprintf("HandleError input argument must be a type of func(iris.Context, int, error) but got: %T", p.HandleError))
51 }
52 }
53 break
54 }
55 }
56
57 return
58}
59
60// MakeHandler creates and returns a handler from a macro template, the handler evaluates each of the parameters if necessary at all.
61// If the template does not contain any dynamic attributes and a special handler is NOT required

Callers 4

NewRouteFunction · 0.92
RegisteredHandlersLenMethod · 0.92
MakeFilterFunction · 0.85
TestCanMakeHandlerFunction · 0.85

Calls 1

CanEvalMethod · 0.80

Tested by 1

TestCanMakeHandlerFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…