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

Function serverFile

http/codegen/server.go:35–117  ·  view source on GitHub ↗

serverFile returns the file implementing the HTTP server.

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

Source from the content-addressed store, hash-verified

33
34// serverFile returns the file implementing the HTTP server.
35func serverFile(genpkg string, svc *expr.HTTPServiceExpr, services *ServicesData) *codegen.File {
36 data := services.Get(svc.Name())
37 svcName := data.Service.PathName
38 fpath := filepath.Join(codegen.Gendir, "http", svcName, "server", "server.go")
39 title := fmt.Sprintf("%s HTTP server", svc.Name())
40 funcs := map[string]any{
41 "join": strings.Join,
42 "hasWebSocket": HasWebSocket,
43 "isWebSocketEndpoint": IsWebSocketEndpoint,
44 "isSSEEndpoint": IsSSEEndpoint,
45 "viewedServerBody": viewedServerBody,
46 "mustDecodeRequest": mustDecodeRequest,
47 "addLeadingSlash": addLeadingSlash,
48 "dir": path.Dir,
49 "isObject": expr.IsObject,
50 }
51 imports := []*codegen.ImportSpec{
52 {Path: "bufio"},
53 {Path: "context"},
54 {Path: "fmt"},
55 {Path: "io"},
56 {Path: "mime/multipart"},
57 {Path: "net/http"},
58 {Path: "path"},
59 {Path: "strings"},
60 {Path: "github.com/gorilla/websocket"},
61 codegen.GoaImport(""),
62 codegen.GoaNamedImport("http", "goahttp"),
63 {Path: genpkg + "/" + svcName, Name: data.Service.PkgName},
64 {Path: genpkg + "/" + svcName + "/" + "views", Name: data.Service.ViewsPkg},
65 }
66 sections := []*codegen.SectionTemplate{
67 codegen.Header(title, "server", imports),
68 }
69
70 sections = append(sections,
71 &codegen.SectionTemplate{Name: "server-struct", Source: httpTemplates.Read(serverStructT), Data: data},
72 &codegen.SectionTemplate{Name: "server-mountpoint", Source: httpTemplates.Read(mountPointStructT), Data: data})
73
74 for _, e := range data.Endpoints {
75 if e.MultipartRequestDecoder != nil {
76 sections = append(sections, &codegen.SectionTemplate{
77 Name: "multipart-request-decoder-type",
78 Source: httpTemplates.Read(multipartRequestDecoderTypeT),
79 Data: e.MultipartRequestDecoder,
80 })
81 }
82 }
83
84 sections = append(sections,
85 &codegen.SectionTemplate{Name: "server-init", Source: httpTemplates.Read(serverInitT), Data: data, FuncMap: funcs},
86 &codegen.SectionTemplate{Name: "server-service", Source: httpTemplates.Read(serverServiceT), Data: data},
87 &codegen.SectionTemplate{Name: "server-use", Source: httpTemplates.Read(serverUseT), Data: data},
88 &codegen.SectionTemplate{Name: "server-method-names", Source: httpTemplates.Read(serverMethodNamesT), Data: data},
89 &codegen.SectionTemplate{Name: "server-mount", Source: httpTemplates.Read(serverMountT), Data: data, FuncMap: funcs})
90
91 for _, e := range data.Endpoints {
92 sections = append(sections,

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