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

Function wrapperFile

codegen/service/interceptors.go:133–216  ·  view source on GitHub ↗

wrapperFile returns the file containing the interceptor wrappers.

(svc *Data)

Source from the content-addressed store, hash-verified

131
132// wrapperFile returns the file containing the interceptor wrappers.
133func wrapperFile(svc *Data) *codegen.File {
134 path := filepath.Join(codegen.Gendir, svc.PathName, "interceptor_wrappers.go")
135
136 var sections []*codegen.SectionTemplate
137 sections = append(sections, codegen.Header("Interceptor wrappers", svc.PkgName, []*codegen.ImportSpec{
138 {Path: "context"},
139 {Path: "fmt"},
140 codegen.GoaImport(""),
141 }))
142
143 // Generate any interceptor stream wrapper struct types first
144 var wrappedServerStreams, wrappedClientStreams []*StreamInterceptorData
145 if len(svc.ServerInterceptors) > 0 {
146 wrappedServerStreams = collectWrappedStreams(svc.ServerInterceptors, true)
147 if len(wrappedServerStreams) > 0 {
148 sections = append(sections, &codegen.SectionTemplate{
149 Name: "server-interceptor-stream-wrapper-types",
150 Source: serviceTemplates.Read(serverInterceptorStreamWrapperTypesT),
151 Data: map[string]any{
152 "WrappedServerStreams": wrappedServerStreams,
153 },
154 })
155 }
156 }
157 if len(svc.ClientInterceptors) > 0 {
158 wrappedClientStreams = collectWrappedStreams(svc.ClientInterceptors, false)
159 if len(wrappedClientStreams) > 0 {
160 sections = append(sections, &codegen.SectionTemplate{
161 Name: "client-interceptor-stream-wrapper-types",
162 Source: serviceTemplates.Read(clientInterceptorStreamWrapperTypesT),
163 Data: map[string]any{
164 "WrappedClientStreams": wrappedClientStreams,
165 },
166 })
167 }
168 }
169
170 // Generate the interceptor wrapper functions next (only once)
171 if len(svc.ServerInterceptors) > 0 {
172 sections = append(sections, &codegen.SectionTemplate{
173 Name: "server-interceptor-wrappers",
174 Source: serviceTemplates.Read(serverInterceptorWrappersT),
175 Data: map[string]any{
176 "Service": svc.Name,
177 "ServerInterceptors": svc.ServerInterceptors,
178 },
179 })
180 }
181 if len(svc.ClientInterceptors) > 0 {
182 sections = append(sections, &codegen.SectionTemplate{
183 Name: "client-interceptor-wrappers",
184 Source: serviceTemplates.Read(clientInterceptorWrappersT),
185 Data: map[string]any{
186 "Service": svc.Name,
187 "ClientInterceptors": svc.ClientInterceptors,
188 },
189 })
190 }

Callers 1

InterceptorsFilesFunction · 0.85

Calls 4

HeaderFunction · 0.92
GoaImportFunction · 0.92
collectWrappedStreamsFunction · 0.85
ReadMethod · 0.45

Tested by

no test coverage detected