MCPcopy Create free account
hub / github.com/goadesign/goa / serverFile

Function serverFile

grpc/codegen/server.go:29–122  ·  view source on GitHub ↗

serverFile returns the files defining the gRPC server.

(genpkg string, svc *expr.GRPCServiceExpr, services *ServicesData)

Source from the content-addressed store, hash-verified

27
28// serverFile returns the files defining the gRPC server.
29func serverFile(genpkg string, svc *expr.GRPCServiceExpr, services *ServicesData) *codegen.File {
30 var (
31 fpath string
32 sections []*codegen.SectionTemplate
33
34 data = services.Get(svc.Name())
35 )
36 {
37 svcName := data.Service.PathName
38 fpath = filepath.Join(codegen.Gendir, "grpc", svcName, "server", "server.go")
39 imports := []*codegen.ImportSpec{
40 {Path: "context"},
41 {Path: "errors"},
42 codegen.GoaImport(""),
43 codegen.GoaNamedImport("grpc", "goagrpc"),
44 {Path: "google.golang.org/grpc/codes"},
45 {Path: path.Join(genpkg, svcName), Name: data.Service.PkgName},
46 {Path: path.Join(genpkg, svcName, "views"), Name: data.Service.ViewsPkg},
47 {Path: path.Join(genpkg, "grpc", svcName, pbPkgName), Name: data.PkgName},
48 }
49 for _, e := range data.Endpoints {
50 if e.Request.StreamEnvelope != nil {
51 imports = append(imports, &codegen.ImportSpec{Path: "io"})
52 break
53 }
54 }
55 sections = []*codegen.SectionTemplate{
56 codegen.Header(svc.Name()+" gRPC server", "server", imports),
57 {
58 Name: "server-struct",
59 Source: grpcTemplates.Read(grpcServerStructTypeT),
60 Data: data,
61 },
62 }
63 for _, e := range data.Endpoints {
64 if e.ServerStream != nil {
65 sections = append(sections, &codegen.SectionTemplate{
66 Name: "server-stream-struct-type",
67 Source: grpcTemplates.Read(grpcStreamStructTypeT),
68 Data: e.ServerStream,
69 })
70 }
71 }
72 sections = append(sections, &codegen.SectionTemplate{
73 Name: "server-init",
74 Source: grpcTemplates.Read(grpcServerInitT),
75 Data: data,
76 })
77 for _, e := range data.Endpoints {
78 sections = append(sections, &codegen.SectionTemplate{
79 Name: "grpc-handler-init",
80 Source: grpcTemplates.Read(grpcHandlerInitT),
81 Data: e,
82 }, &codegen.SectionTemplate{
83 Name: "server-grpc-interface",
84 Source: grpcTemplates.Read(grpcServerGRPCInterfaceT),
85 Data: e,
86 })

Callers 1

ServerFilesFunction · 0.70

Calls 6

GoaImportFunction · 0.92
GoaNamedImportFunction · 0.92
HeaderFunction · 0.92
NameMethod · 0.65
GetMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected