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)
| 40 | // - Response body fields (if the body is a struct) and header variables hold |
| 41 | // pointers when not required and have no default value. |
| 42 | func 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()) |