-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathdesign.go
102 lines (89 loc) · 2.8 KB
/
design.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package expr
import (
"fmt"
"goa.design/goa/v3/eval"
"goa.design/goa/v3/expr"
model "goa.design/model/pkg"
)
type (
// Design contains the AST generated from the DSL.
Design struct {
Name string
Description string
Version string
Model *Model
Views *Views
}
)
// Root is the design root expression.
var Root = &Design{Model: &Model{}, Views: &Views{}}
// Register design root with eval engine.
func init() {
eval.Register(Root) // nolint: errcheck
}
// WalkSets iterates over the elements and views.
// Elements DSL cannot be executed on init because all elements must first be
// loaded and their IDs captured in the registry before relationships can be
// built with DSL.
func (d *Design) WalkSets(walk eval.SetWalker) {
// 1. Model
walk([]eval.Expression{d.Model})
// 2. People
walk(eval.ToExpressionSet(d.Model.People))
// 3. Systems
walk(eval.ToExpressionSet(d.Model.Systems))
// 4. Containers
for _, s := range d.Model.Systems {
walk(eval.ToExpressionSet(s.Containers))
}
// 5. Components
for _, s := range d.Model.Systems {
for _, c := range s.Containers {
walk(eval.ToExpressionSet(c.Components))
}
}
// 6. Deployment environments
walkDeploymentNodes(d.Model.DeploymentNodes, walk)
// 7. Views
walk([]eval.Expression{d.Views})
}
// 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 (*Design) Packages() []string {
return []string{
"goa.design/model/expr",
"goa.design/model/dsl",
fmt.Sprintf("goa.design/model@%s/expr", model.Version()),
fmt.Sprintf("goa.design/model@%s/dsl", model.Version()),
}
}
// DependsOn tells the eval engine to run the goa DSL first.
func (*Design) DependsOn() []eval.Root { return []eval.Root{expr.Root} }
// EvalName returns the generic expression name used in error messages.
func (*Design) EvalName() string { return "root" }
func walkDeploymentNodes(n []*DeploymentNode, walk eval.SetWalker) {
if n == nil {
return
}
walk(eval.ToExpressionSet(n))
for _, d := range n {
walk(eval.ToExpressionSet(d.InfrastructureNodes))
walk(eval.ToExpressionSet(d.ContainerInstances))
walkDeploymentNodes(d.Children, walk)
}
}
// Person returns the person with the given name if any, nil otherwise.
func (d *Design) Person(name string) *Person {
return d.Model.Person(name)
}
// SoftwareSystem returns the software system with the given name if any, nil
// otherwise.
func (d *Design) SoftwareSystem(name string) *SoftwareSystem {
return d.Model.SoftwareSystem(name)
}
// DeploymentNode returns the deployment node with the given name in the given
// environment if any, nil otherwise.
func (d *Design) DeploymentNode(env, name string) *DeploymentNode {
return d.Model.DeploymentNode(env, name)
}