MCPcopy Create free account
hub / github.com/goadesign/goa / Service

Function Service

codegen/generator/service.go:13–53  ·  view source on GitHub ↗

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.

(genpkg string, roots []eval.Root)

Source from the content-addressed store, hash-verified

11// the service code. It returns an error if the roots slice does not include
12// a goa design.
13func Service(genpkg string, roots []eval.Root) ([]*codegen.File, error) {
14 var files []*codegen.File
15 var userTypePkgs = make(map[string][]string)
16 for _, root := range roots {
17 r, ok := root.(*expr.RootExpr)
18 if !ok {
19 continue
20 }
21 // Create service data
22 services := service.NewServicesData(r)
23
24 for _, s := range r.Services {
25 d := services.Get(s.Name)
26 service.SetUserTypeImports(genpkg, d)
27
28 // Make sure service is first so name scope is
29 // properly initialized.
30 svcFiles := service.Files(genpkg, s, services, userTypePkgs)
31 addServiceImports(svcFiles, d)
32 files = append(files, svcFiles...)
33
34 endpointFiles := []*codegen.File{
35 service.EndpointFile(genpkg, s, services),
36 service.ClientFile(genpkg, s, services),
37 }
38 addServiceImports(endpointFiles, d)
39 files = append(files, endpointFiles...)
40
41 if f := service.ViewsFile(genpkg, s, services); f != nil {
42 addServiceImports([]*codegen.File{f}, d)
43 files = append(files, f)
44 }
45 convFiles, err := service.ConvertFiles(r, s, services)
46 if err != nil {
47 return nil, err
48 }
49 files = append(files, convFiles...)
50 }
51 }
52 return files, nil
53}
54
55func addServiceImports(files []*codegen.File, d *service.Data) {
56 for _, f := range files {

Callers 11

dsls.goFile · 0.50
views_dsls.goFile · 0.50
convert_dsls.goFile · 0.50
security_dsls.goFile · 0.50
service_dsls.goFile · 0.50
create_dsls.goFile · 0.50
endpoint_dsls.goFile · 0.50

Calls 9

GetMethod · 0.95
NewServicesDataFunction · 0.92
SetUserTypeImportsFunction · 0.92
FilesFunction · 0.92
EndpointFileFunction · 0.92
ClientFileFunction · 0.92
ViewsFileFunction · 0.92
ConvertFilesFunction · 0.92
addServiceImportsFunction · 0.85

Tested by

no test coverage detected