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

Function serverType

http/codegen/server_types.go:42–218  ·  view source on GitHub ↗

serverType return the file containing the type definitions used by the HTTP transport for the given service server. Below are the rules governing whether values are pointers or not. Note that the rules only applies to values that hold primitive types, values that hold slices, maps or objects always

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

Source from the content-addressed store, hash-verified

40// - Response body fields (if the body is a struct) and header variables hold
41// pointers when not required and have no default value.
42func serverType(genpkg string, svc *expr.HTTPServiceExpr, services *ServicesData) *codegen.File {
43 var (
44 path string
45 data = services.Get(svc.Name())
46 svcName = data.Service.PathName
47 )
48 path = filepath.Join(codegen.Gendir, "http", svcName, "server", "types.go")
49 imports := []*codegen.ImportSpec{
50 {Path: "encoding/json"},
51 {Path: "fmt"},
52 {Path: "unicode/utf8"},
53 {Path: genpkg + "/" + svcName, Name: data.Service.PkgName},
54 codegen.GoaImport(""),
55 {Path: genpkg + "/" + svcName + "/" + "views", Name: data.Service.ViewsPkg},
56 }
57 header := codegen.Header(svc.Name()+" HTTP server types", "server", imports)
58
59 var (
60 initData []*InitData
61 validatedTypes []*TypeData
62
63 sections = []*codegen.SectionTemplate{header}
64 )
65
66 // request body types
67 for _, a := range svc.HTTPEndpoints {
68 adata := data.Endpoint(a.Name())
69 if data := adata.Payload.Request.ServerBody; data != nil {
70 if data.Def != "" {
71 sections = append(sections, &codegen.SectionTemplate{
72 Name: "request-body-type-decl",
73 Source: httpTemplates.Read(typeDeclT),
74 Data: data,
75 })
76 }
77 if data.ValidateDef != "" {
78 validatedTypes = append(validatedTypes, data)
79 }
80 }
81 if adata.ServerWebSocket != nil && !adata.Method.IsJSONRPC {
82 if data := adata.ServerWebSocket.Payload; data != nil {
83 if data.Def != "" {
84 sections = append(sections, &codegen.SectionTemplate{
85 Name: "request-stream-payload-type-decl",
86 Source: httpTemplates.Read(typeDeclT),
87 Data: data,
88 })
89 }
90 if data.ValidateDef != "" {
91 validatedTypes = append(validatedTypes, data)
92 }
93 }
94 }
95 }
96
97 // response body types
98 for _, a := range svc.HTTPEndpoints {
99 adata := data.Endpoint(a.Name())

Callers 4

TestCookieAPIKeySecurityFunction · 0.70
TestServerTypesFunction · 0.70
ServerTypeFilesFunction · 0.70
TestPayloadConstructorFunction · 0.70

Calls 7

GoaImportFunction · 0.92
HeaderFunction · 0.92
IsWebSocketEndpointFunction · 0.85
NameMethod · 0.65
GetMethod · 0.45
EndpointMethod · 0.45
ReadMethod · 0.45

Tested by 3

TestCookieAPIKeySecurityFunction · 0.56
TestServerTypesFunction · 0.56
TestPayloadConstructorFunction · 0.56