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

Function exampleServiceFile

codegen/service/example_svc.go:60–113  ·  view source on GitHub ↗

exampleServiceFile returns a basic implementation of the given service.

(genpkg string, _ *expr.RootExpr, svc *expr.ServiceExpr, services *ServicesData, apipkg string)

Source from the content-addressed store, hash-verified

58
59// exampleServiceFile returns a basic implementation of the given service.
60func exampleServiceFile(genpkg string, _ *expr.RootExpr, svc *expr.ServiceExpr, services *ServicesData, apipkg string) *codegen.File {
61 data := services.Get(svc.Name)
62 svcName := data.PathName
63 fpath := svcName + ".go"
64 if _, err := os.Stat(fpath); !os.IsNotExist(err) {
65 return nil // file already exists, skip it.
66 }
67 specs := []*codegen.ImportSpec{
68 {Path: "io"},
69 {Path: "context"},
70 {Path: "fmt"},
71 {Path: "strings"},
72 {Path: path.Join(genpkg, svcName), Name: data.PkgName},
73 {Path: "goa.design/clue/log"},
74 {Path: "goa.design/goa/v3/security"},
75 }
76 sections := []*codegen.SectionTemplate{
77 codegen.Header("", apipkg, specs),
78 {
79 Name: "basic-service-struct",
80 Source: serviceTemplates.Read(exampleServiceStructT),
81 Data: data,
82 }, {
83 Name: "basic-service-init",
84 Source: serviceTemplates.Read(exampleServiceInitT),
85 Data: data,
86 },
87 }
88 if len(data.Schemes) > 0 {
89 sections = append(sections, &codegen.SectionTemplate{
90 Name: "security-authfuncs",
91 Source: serviceTemplates.Read(exampleSecurityAuthfuncsT),
92 Data: data,
93 })
94 }
95 for _, m := range svc.Methods {
96 sections = append(sections, basicEndpointSection(m, data))
97 }
98
99 // Add HandleStream method for JSON-RPC WebSocket services (not SSE)
100 if hasJSONRPCStreaming(data) && !isJSONRPCSSE(services, svc) {
101 sections = append(sections, &codegen.SectionTemplate{
102 Name: "jsonrpc-handle-stream",
103 Source: serviceTemplates.Read(jsonrpcHandleStreamT),
104 Data: data,
105 })
106 }
107
108 return &codegen.File{
109 Path: fpath,
110 SectionTemplates: sections,
111 SkipExist: true,
112 }
113}
114
115// basicEndpointSection returns a section with a basic implementation for the
116// given method.

Callers 1

ExampleServiceFilesFunction · 0.85

Calls 6

HeaderFunction · 0.92
basicEndpointSectionFunction · 0.85
hasJSONRPCStreamingFunction · 0.85
isJSONRPCSSEFunction · 0.85
GetMethod · 0.45
ReadMethod · 0.45

Tested by

no test coverage detected