wrapperFile returns the file containing the interceptor wrappers.
(svc *Data)
| 131 | |
| 132 | // wrapperFile returns the file containing the interceptor wrappers. |
| 133 | func 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 | } |
no test coverage detected