clientFile returns the file implementing the gRPC client.
(genpkg string, svc *expr.GRPCServiceExpr, services *ServicesData)
| 25 | |
| 26 | // clientFile returns the file implementing the gRPC client. |
| 27 | func clientFile(genpkg string, svc *expr.GRPCServiceExpr, services *ServicesData) *codegen.File { |
| 28 | var ( |
| 29 | fpath string |
| 30 | sections []*codegen.SectionTemplate |
| 31 | |
| 32 | data = services.Get(svc.Name()) |
| 33 | ) |
| 34 | { |
| 35 | svcName := data.Service.PathName |
| 36 | fpath = filepath.Join(codegen.Gendir, "grpc", svcName, "client", "client.go") |
| 37 | imports := []*codegen.ImportSpec{ |
| 38 | {Path: "context"}, |
| 39 | {Path: "google.golang.org/grpc"}, |
| 40 | codegen.GoaImport(""), |
| 41 | codegen.GoaNamedImport("grpc", "goagrpc"), |
| 42 | codegen.GoaNamedImport("grpc/pb", "goapb"), |
| 43 | {Path: path.Join(genpkg, svcName), Name: data.Service.PkgName}, |
| 44 | {Path: path.Join(genpkg, svcName, "views"), Name: data.Service.ViewsPkg}, |
| 45 | {Path: path.Join(genpkg, "grpc", svcName, pbPkgName), Name: data.PkgName}, |
| 46 | } |
| 47 | sections = []*codegen.SectionTemplate{ |
| 48 | codegen.Header(svc.Name()+" gRPC client", "client", imports), |
| 49 | } |
| 50 | sections = append(sections, &codegen.SectionTemplate{ |
| 51 | Name: "client-struct", |
| 52 | Source: grpcTemplates.Read(grpcClientStructT), |
| 53 | Data: data, |
| 54 | }) |
| 55 | for _, e := range data.Endpoints { |
| 56 | if e.ClientStream != nil { |
| 57 | sections = append(sections, &codegen.SectionTemplate{ |
| 58 | Name: "client-stream-struct-type", |
| 59 | Source: grpcTemplates.Read(grpcStreamStructTypeT), |
| 60 | Data: e.ClientStream, |
| 61 | }) |
| 62 | } |
| 63 | } |
| 64 | sections = append(sections, &codegen.SectionTemplate{ |
| 65 | Name: "grpc-client-init", |
| 66 | Source: grpcTemplates.Read(grpcClientInitT), |
| 67 | Data: data, |
| 68 | }) |
| 69 | for _, e := range data.Endpoints { |
| 70 | sections = append(sections, &codegen.SectionTemplate{ |
| 71 | Name: "client-endpoint-init", |
| 72 | Source: grpcTemplates.Read(grpcClientEndpointInitT), |
| 73 | Data: e, |
| 74 | }) |
| 75 | } |
| 76 | for _, e := range data.Endpoints { |
| 77 | if e.ClientStream != nil { |
| 78 | if e.ClientStream.RecvConvert != nil { |
| 79 | sections = append(sections, &codegen.SectionTemplate{ |
| 80 | Name: "client-stream-recv", |
| 81 | Source: grpcTemplates.Read(grpcStreamRecvT), |
| 82 | Data: e.ClientStream, |
| 83 | }) |
| 84 | } |
no test coverage detected