-
-
Notifications
You must be signed in to change notification settings - Fork 564
/
Copy pathservice.go
48 lines (45 loc) Β· 1.25 KB
/
service.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
package generator
import (
"fmt"
"goa.design/goa/codegen"
"goa.design/goa/codegen/service"
"goa.design/goa/eval"
"goa.design/goa/expr"
)
// Service iterates through the roots and returns the files needed to render
// the service code. It returns an error if the roots slice does not include
// a goa design.
func Service(genpkg string, roots []eval.Root) ([]*codegen.File, error) {
var files []*codegen.File
for _, root := range roots {
switch r := root.(type) {
case *expr.RootExpr:
for _, s := range r.Services {
// Make sure service is first so name scope is
// properly initialized.
files = append(files, service.File(genpkg, s))
files = append(files, service.EndpointFile(genpkg, s))
files = append(files, service.ClientFile(s))
if f := service.ViewsFile(genpkg, s); f != nil {
files = append(files, f)
}
for _, f := range files {
if len(f.SectionTemplates) > 0 {
service.AddServiceDataMetaTypeImports(f.SectionTemplates[0], s)
}
}
f, err := service.ConvertFile(r, s)
if err != nil {
return nil, err
}
if f != nil {
files = append(files, f)
}
}
}
}
if len(files) == 0 {
return nil, fmt.Errorf("design must define at least one service")
}
return files, nil
}