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)
| 11 | // the service code. It returns an error if the roots slice does not include |
| 12 | // a goa design. |
| 13 | func 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 | |
| 55 | func addServiceImports(files []*codegen.File, d *service.Data) { |
| 56 | for _, f := range files { |
no test coverage detected