ExampleServiceFiles returns a basic service implementation for every service expression.
(genpkg string, root *expr.RootExpr, services *ServicesData)
| 36 | // ExampleServiceFiles returns a basic service implementation for every |
| 37 | // service expression. |
| 38 | func ExampleServiceFiles(genpkg string, root *expr.RootExpr, services *ServicesData) []*codegen.File { |
| 39 | // determine the unique API package name different from the service names |
| 40 | scope := codegen.NewNameScope() |
| 41 | for _, svc := range root.Services { |
| 42 | s := services.Get(svc.Name) |
| 43 | if s == nil { |
| 44 | panic("unknown service, " + svc.Name) // bug |
| 45 | } |
| 46 | scope.Unique(s.PkgName) |
| 47 | } |
| 48 | apipkg := scope.Unique(strings.ToLower(codegen.Goify(root.API.Name, false)), "api") |
| 49 | |
| 50 | var fw []*codegen.File |
| 51 | for _, svc := range root.Services { |
| 52 | if f := exampleServiceFile(genpkg, root, svc, services, apipkg); f != nil { |
| 53 | fw = append(fw, f) |
| 54 | } |
| 55 | } |
| 56 | return fw |
| 57 | } |
| 58 | |
| 59 | // exampleServiceFile returns a basic implementation of the given service. |
| 60 | func exampleServiceFile(genpkg string, _ *expr.RootExpr, svc *expr.ServiceExpr, services *ServicesData, apipkg string) *codegen.File { |