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

Function serverType

grpc/codegen/server_types.go:22–135  ·  view source on GitHub ↗

serverType returns the file defining the gRPC server types.

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

Source from the content-addressed store, hash-verified

20
21// serverType returns the file defining the gRPC server types.
22func 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 }

Callers 1

ServerTypeFilesFunction · 0.70

Calls 9

GoaImportFunction · 0.92
HeaderFunction · 0.92
UserTypeLocationFunction · 0.92
hasAnyTypeFunction · 0.85
PackageNameMethod · 0.80
NameMethod · 0.65
GetMethod · 0.45
EndpointMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected