forked from goadesign/goa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transport.go
53 lines (47 loc) · 1.7 KB
/
transport.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
package generator
import (
"fmt"
"goa.design/goa/codegen"
"goa.design/goa/codegen/service"
"goa.design/goa/eval"
"goa.design/goa/expr"
grpccodegen "goa.design/goa/grpc/codegen"
httpcodegen "goa.design/goa/http/codegen"
)
// Transport iterates through the roots and returns the files needed to render
// the transport code. It returns an error if the roots slice does not include
// at least one transport design.
func Transport(genpkg string, roots []eval.Root) ([]*codegen.File, error) {
var files []*codegen.File
for _, root := range roots {
r, ok := root.(*expr.RootExpr)
if !ok {
continue // could be a plugin root expression
}
// HTTP
files = append(files, httpcodegen.ServerFiles(genpkg, r)...)
files = append(files, httpcodegen.ClientFiles(genpkg, r)...)
files = append(files, httpcodegen.ServerTypeFiles(genpkg, r)...)
files = append(files, httpcodegen.ClientTypeFiles(genpkg, r)...)
files = append(files, httpcodegen.PathFiles(r)...)
files = append(files, httpcodegen.ClientCLIFiles(genpkg, r)...)
// GRPC
files = append(files, grpccodegen.ProtoFiles(genpkg, r)...)
files = append(files, grpccodegen.ServerFiles(genpkg, r)...)
files = append(files, grpccodegen.ClientFiles(genpkg, r)...)
files = append(files, grpccodegen.ServerTypeFiles(genpkg, r)...)
files = append(files, grpccodegen.ClientTypeFiles(genpkg, r)...)
files = append(files, grpccodegen.ClientCLIFiles(genpkg, r)...)
for _, f := range files {
if len(f.SectionTemplates) > 0 {
for _, s := range r.Services {
service.AddServiceDataMetaTypeImports(f.SectionTemplates[0], s)
}
}
}
}
if len(files) == 0 {
return nil, fmt.Errorf("transport: no HTTP/gRPC design found")
}
return files, nil
}