-
-
Notifications
You must be signed in to change notification settings - Fork 564
/
Copy pathhelpers.go
38 lines (36 loc) Β· 1.01 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package expr
import (
"goa.design/goa/eval"
)
// findKey finds the given key in the endpoint expression and returns the
// transport element name and the position (header, query, or body for HTTP or
// message, metadata for gRPC endpoint).
func findKey(exp eval.Expression, keyAtt string) (string, string) {
switch e := exp.(type) {
case *HTTPEndpointExpr:
if n, exists := e.Params.FindKey(keyAtt); exists {
return n, "query"
} else if n, exists := e.Headers.FindKey(keyAtt); exists {
return n, "header"
} else if e.Body == nil {
return "", "header"
}
if _, ok := e.Body.Meta["http:body"]; ok {
if e.Body.Find(keyAtt) != nil {
return keyAtt, "body"
}
if m, ok := e.Body.Meta["origin:attribute"]; ok && m[0] == keyAtt {
return keyAtt, "body"
}
}
return "", "header"
case *GRPCEndpointExpr:
if e.Request.Find(keyAtt) != nil {
return keyAtt, "message"
} else if n, exists := e.Metadata.FindKey(keyAtt); exists {
return n, "metadata"
}
return "", "metadata"
}
return "", ""
}