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

Method InvokeHandler

pkg/controller/handler.go:43–121  ·  view source on GitHub ↗
(c *routing.Context)

Source from the content-addressed store, hash-verified

41}
42
43func (controller *Controller) InvokeHandler(c *routing.Context) error {
44 externalRequestID := string(c.Request.Header.Peek(api.HeaderXRequestID))
45 invokeType := strings.ToLower(string(c.Request.Header.Peek(api.HeaderInvokeType)))
46 triggerType := strings.ToLower(string(c.Request.Header.Peek(api.BceFaasTriggerKey)))
47 accountID := string(c.Request.Header.Peek(api.HeaderXAccountID))
48 authorization := string(c.Request.Header.Peek(api.HeaderAuthorization))
49 requestID := id.GetRequestID()
50 if externalRequestID == "" {
51 externalRequestID = requestID
52 }
53
54 if invokeType == "" {
55 invokeType = api.InvokeTypeCommon
56 }
57 if triggerType == "" {
58 triggerType = api.TriggerTypeGeneric
59 }
60
61 var clientMode string
62 if invokeType == api.InvokeTypeEvent || invokeType == api.InvokeTypeMqhub {
63 clientMode = ClientModeInside
64 }
65 if triggerType == api.TriggerTypeVscode {
66 clientMode = ClientModeInside
67 }
68
69 ctx := InvokeContext{
70 RunOptions: controller.runOptions,
71 ExternalRequestID: externalRequestID,
72 RequestID: requestID,
73 AccountID: accountID,
74 Authorization: authorization,
75 CallerUser: &api.User{
76 ID: accountID,
77 },
78 Clients: controller.NewClients(clientMode),
79 Request: generateInvokeRequest(c),
80 Response: api.NewInvokeProxyResponseWithRequestID(externalRequestID),
81 Logger: logs.NewLogger().WithField("request_id", requestID).
82 WithField("external_request_id", externalRequestID).WithField("invoke-type", invokeType),
83 LogType: api.GetLogType(c),
84 LogToBody: api.GetLogToBody(c),
85 InvokeType: invokeType,
86 TriggerType: triggerType,
87 }
88
89 funcName := c.Param("functionName")
90 if !api.RegfunctionName.MatchString(funcName) {
91 ctx.FunctionBRN = funcName
92 } else {
93 qualifier := string(c.QueryArgs().Peek("Qualifier"))
94 if qualifier == "" {
95 c.Response.SetStatusCode(http.StatusBadRequest)
96 err := innerErr.NewInvalidParameterValueException("missing query parameter Qualifier", nil)
97 bodyData, _ := json.Marshal(err)
98 c.Response.SetBody(bodyData)
99 return err
100 }

Callers

nothing calls this directly

Calls 15

NewClientsMethod · 0.95
InvokeMethod · 0.95
GetRequestIDFunction · 0.92
NewLoggerFunction · 0.92
GetLogTypeFunction · 0.92
GetLogToBodyFunction · 0.92
MarshalFunction · 0.92
generateInvokeRequestFunction · 0.85
NewInvokeMetricsFunction · 0.85
WithFieldMethod · 0.80
ParamMethod · 0.80

Tested by

no test coverage detected