interceptorFile returns the file defining the interceptors. This method is called twice, once for the server and once for the client.
(svc *Data, server bool)
| 31 | // interceptorFile returns the file defining the interceptors. |
| 32 | // This method is called twice, once for the server and once for the client. |
| 33 | func interceptorFile(svc *Data, server bool) *codegen.File { |
| 34 | filename := "client_interceptors.go" |
| 35 | template := clientInterceptorsT |
| 36 | section := "client-interceptors-type" |
| 37 | desc := "Client Interceptors" |
| 38 | if server { |
| 39 | filename = "service_interceptors.go" |
| 40 | template = serverInterceptorsT |
| 41 | section = "server-interceptors-type" |
| 42 | desc = "Server Interceptors" |
| 43 | } |
| 44 | desc = svc.Name + desc |
| 45 | path := filepath.Join(codegen.Gendir, svc.PathName, filename) |
| 46 | |
| 47 | interceptors := svc.ServerInterceptors |
| 48 | if !server { |
| 49 | interceptors = svc.ClientInterceptors |
| 50 | } |
| 51 | |
| 52 | // We don't want to generate duplicate interceptor info data structures for |
| 53 | // interceptors that are both server and client side so remove interceptors |
| 54 | // that are both server and client side when generating the client. |
| 55 | if !server { |
| 56 | names := make(map[string]struct{}, len(svc.ServerInterceptors)) |
| 57 | for _, sin := range svc.ServerInterceptors { |
| 58 | names[sin.Name] = struct{}{} |
| 59 | } |
| 60 | filtered := make([]*InterceptorData, 0, len(interceptors)) |
| 61 | for _, in := range interceptors { |
| 62 | if _, ok := names[in.Name]; !ok { |
| 63 | filtered = append(filtered, in) |
| 64 | } |
| 65 | } |
| 66 | interceptors = filtered |
| 67 | } |
| 68 | |
| 69 | sections := []*codegen.SectionTemplate{ |
| 70 | codegen.Header(desc, svc.PkgName, []*codegen.ImportSpec{ |
| 71 | {Path: "context"}, |
| 72 | codegen.GoaImport(""), |
| 73 | }), |
| 74 | { |
| 75 | Name: section, |
| 76 | Source: serviceTemplates.Read(template), |
| 77 | Data: svc, |
| 78 | }, |
| 79 | } |
| 80 | if len(interceptors) > 0 { |
| 81 | sections = append(sections, &codegen.SectionTemplate{ |
| 82 | Name: "interceptor-types", |
| 83 | Source: serviceTemplates.Read(interceptorsTypesT), |
| 84 | Data: interceptors, |
| 85 | FuncMap: map[string]any{ |
| 86 | "hasPrivateImplementationTypes": hasPrivateImplementationTypes, |
| 87 | }, |
| 88 | }) |
| 89 | } |
| 90 |
no test coverage detected