MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / wrapRouter

Function wrapRouter

cmd/controller/app/server.go:63–116  ·  view source on GitHub ↗
(controller *controller.Controller, runOptions *options.ControllerOptions)

Source from the content-addressed store, hash-verified

61}
62
63func wrapRouter(controller *controller.Controller, runOptions *options.ControllerOptions) func(ctx *fasthttp.RequestCtx) {
64 router := routing.New()
65 router.Get("/healthz", controller.HealthzHandler)
66
67 router.Post("/v1/functions/<functionName>/invocations", controller.InvokeHandler)
68 router.Get("/v1/runtimes", controller.ListRuntimesHandler)
69 router.Get("/v1/resource", controller.GetResourceHandler)
70 router.Post("/v1/runtimes/<runtimeID>/invalidate", controller.InvalidateRuntime)
71
72 if runOptions.HTTPEnhanced {
73 logs.V(9).Info("equipped with http trigger feature")
74 router.Any(`/<userID:\w+>/<functionName>`, httptrigger.ProxyHandler)
75 router.Any(`/<userID:\w+>/<functionName>/<version>`, httptrigger.ProxyHandler)
76 }
77
78 var enhanceRouting bool
79 if runOptions.RecommendedOptions.Features.EnableMetrics || runOptions.RecommendedOptions.Features.EnableProfiling {
80 enhanceRouting = true
81 }
82 logs.Infof("enhanceRouting flag %v", enhanceRouting)
83 if !enhanceRouting {
84 return router.HandleRequest
85 }
86
87 enhanceHandler := func(ctx *fasthttp.RequestCtx) {
88 urlPath := string(ctx.Path())
89 if runOptions.RecommendedOptions.Features.EnableProfiling && strings.HasPrefix(urlPath, "/debug/pprof/") {
90 logs.V(9).Info("enable profiling")
91 switch urlPath {
92 case "/debug/pprof/cmdline":
93 fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Cmdline)(ctx)
94 case "/debug/pprof/profile":
95 fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Profile)(ctx)
96 case "/debug/pprof/symbol":
97 fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Symbol)(ctx)
98 case "/debug/pprof/trace":
99 fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Trace)(ctx)
100 default:
101 fasthttpadaptor.NewFastHTTPHandlerFunc(pprof.Index)(ctx)
102 }
103 return
104 }
105
106 if runOptions.RecommendedOptions.Features.EnableMetrics && strings.HasPrefix(urlPath, "/metrics") {
107 logs.V(9).Info("enable metrics")
108 fasthttpadaptor.NewFastHTTPHandler(promhttp.Handler())(ctx)
109 return
110 }
111
112 router.HandleRequest(ctx)
113 return
114 }
115 return enhanceHandler
116}

Callers 1

RunFunction · 0.70

Calls 7

VFunction · 0.92
InfofFunction · 0.92
NewMethod · 0.80
GetMethod · 0.65
PostMethod · 0.65
InfoMethod · 0.65
PathMethod · 0.45

Tested by

no test coverage detected