MCPcopy Create free account
hub / github.com/goadesign/goa / findKey

Function findKey

expr/helpers.go:17–47  ·  view source on GitHub ↗

findKey finds the given key in the endpoint expression and returns the transport element name and the position (header, query, cookie, or body for HTTP or message, metadata for gRPC endpoint).

(exp eval.Expression, keyAtt string)

Source from the content-addressed store, hash-verified

15// transport element name and the position (header, query, cookie, or body for
16// HTTP or message, metadata for gRPC endpoint).
17func findKey(exp eval.Expression, keyAtt string) (string, string) {
18 switch e := exp.(type) {
19 case *HTTPEndpointExpr:
20 if n, exists := e.Params.FindKey(keyAtt); exists {
21 return n, "query"
22 } else if n, exists := e.Headers.FindKey(keyAtt); exists {
23 return n, "header"
24 } else if n, exists := e.Cookies.FindKey(keyAtt); exists {
25 return n, "cookie"
26 } else if e.Body == nil {
27 return "", "header"
28 }
29 if _, ok := e.Body.Meta["http:body"]; ok {
30 if e.Body.Find(keyAtt) != nil {
31 return keyAtt, "body"
32 }
33 if m, ok := e.Body.Meta["origin:attribute"]; ok && m[0] == keyAtt {
34 return keyAtt, "body"
35 }
36 }
37 return "", "header"
38 case *GRPCEndpointExpr:
39 if e.Request.Find(keyAtt) != nil {
40 return keyAtt, "message"
41 } else if n, exists := e.Metadata.FindKey(keyAtt); exists {
42 return n, "metadata"
43 }
44 return "", "metadata"
45 }
46 return "", ""
47}

Callers 3

FinalizeMethod · 0.85
FinalizeMethod · 0.85

Calls 2

FindKeyMethod · 0.80
FindMethod · 0.80

Tested by

no test coverage detected