serverType returns the file defining the gRPC server types.
(genpkg string, svc *expr.GRPCServiceExpr, services *ServicesData)
| 20 | |
| 21 | // serverType returns the file defining the gRPC server types. |
| 22 | func serverType(genpkg string, svc *expr.GRPCServiceExpr, services *ServicesData) *codegen.File { |
| 23 | var ( |
| 24 | initData []*InitData |
| 25 | |
| 26 | sd = services.Get(svc.Name()) |
| 27 | foundInits = make(map[string]struct{}) |
| 28 | ) |
| 29 | { |
| 30 | collect := func(c *ConvertData) { |
| 31 | if c.Init != nil { |
| 32 | initData = append(initData, c.Init) |
| 33 | } |
| 34 | } |
| 35 | for _, a := range svc.GRPCEndpoints { |
| 36 | ed := sd.Endpoint(a.Name()) |
| 37 | if c := ed.Request.ServerConvert; c != nil { |
| 38 | collect(c) |
| 39 | } |
| 40 | if c := ed.Response.ServerConvert; c != nil { |
| 41 | collect(c) |
| 42 | } |
| 43 | if ed.ServerStream != nil { |
| 44 | if c := ed.ServerStream.SendConvert; c != nil { |
| 45 | collect(c) |
| 46 | } |
| 47 | if c := ed.ServerStream.RecvConvert; c != nil { |
| 48 | collect(c) |
| 49 | } |
| 50 | } |
| 51 | for _, e := range ed.Errors { |
| 52 | if c := e.Response.ServerConvert; c != nil { |
| 53 | collect(c) |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | var ( |
| 60 | fpath string |
| 61 | sections []*codegen.SectionTemplate |
| 62 | ) |
| 63 | { |
| 64 | svcName := sd.Service.PathName |
| 65 | fpath = filepath.Join(codegen.Gendir, "grpc", svcName, "server", "types.go") |
| 66 | imports := []*codegen.ImportSpec{ |
| 67 | {Path: "unicode/utf8"}, |
| 68 | codegen.GoaImport(""), |
| 69 | {Path: path.Join(genpkg, svcName), Name: sd.Service.PkgName}, |
| 70 | {Path: path.Join(genpkg, svcName, "views"), Name: sd.Service.ViewsPkg}, |
| 71 | {Path: path.Join(genpkg, "grpc", svcName, pbPkgName), Name: sd.PkgName}, |
| 72 | } |
| 73 | // Add imports if Any type is used |
| 74 | needsAnyTypeImports := false |
| 75 | for _, e := range svc.GRPCEndpoints { |
| 76 | if hasAnyType(e.MethodExpr.Payload) || hasAnyType(e.MethodExpr.Result) { |
| 77 | needsAnyTypeImports = true |
| 78 | break |
| 79 | } |
no test coverage detected