-
Notifications
You must be signed in to change notification settings - Fork 34
/
root.go
60 lines (52 loc) · 1.58 KB
/
root.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package expr
import (
"goa.design/goa/eval"
"goa.design/goa/expr"
)
// Root is the design root expression.
var Root = &RootExpr{
APIOrigins: map[string]*OriginExpr{},
ServiceOrigins: map[string]*OriginExpr{},
}
type (
// RootExpr keeps track of the CORS origins defined in the design.
RootExpr struct {
// APIOrigins lists all the CORS definitions indexed by origin string
// at the API level.
APIOrigins map[string]*OriginExpr
// ServiceOrigins lists all the CORS definitions indexed by origin string
// at the service level.
ServiceOrigins map[string]*OriginExpr
}
)
// Register design root with eval engine.
func init() {
eval.Register(Root)
}
// EvalName returns the name used in error messages.
func (r *RootExpr) EvalName() string {
return "CORS plugin"
}
// WalkSets iterates over the API-level and service-level CORS definitions.
func (r *RootExpr) WalkSets(walk eval.SetWalker) {
oexps := make(eval.ExpressionSet, 0, len(r.APIOrigins))
for _, o := range r.APIOrigins {
oexps = append(oexps, o)
}
walk(oexps)
oexps = make(eval.ExpressionSet, 0, len(r.ServiceOrigins))
for _, o := range r.ServiceOrigins {
oexps = append(oexps, o)
}
walk(oexps)
}
// DependsOn tells the eval engine to run the goa DSL first.
func (r *RootExpr) DependsOn() []eval.Root {
return []eval.Root{expr.Root}
}
// Packages returns the import path to the Go packages that make
// up the DSL. This is used to skip frames that point to files
// in these packages when computing the location of errors.
func (r *RootExpr) Packages() []string {
return []string{"goa.design/plugins/cors/dsl"}
}