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