EchoInterceptorFactories.swift 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Copyright 2021, gRPC Authors All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import EchoModel
  17. import GRPC
  18. // MARK: - Client
  19. internal final class EchoClientInterceptors: Echo_EchoClientInterceptorFactoryProtocol {
  20. typealias Factory = @Sendable () -> ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>
  21. private let factories: [Factory]
  22. internal init(_ factories: Factory...) {
  23. self.factories = factories
  24. }
  25. private func makeInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>] {
  26. return self.factories.map { $0() }
  27. }
  28. func makeGetInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>] {
  29. return self.makeInterceptors()
  30. }
  31. func makeExpandInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>] {
  32. return self.makeInterceptors()
  33. }
  34. func makeCollectInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>] {
  35. return self.makeInterceptors()
  36. }
  37. func makeUpdateInterceptors() -> [ClientInterceptor<Echo_EchoRequest, Echo_EchoResponse>] {
  38. return self.makeInterceptors()
  39. }
  40. }
  41. // MARK: - Server
  42. internal final class EchoServerInterceptors: Echo_EchoServerInterceptorFactoryProtocol {
  43. typealias Factory = @Sendable () -> ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>
  44. private let factories: [Factory]
  45. internal init(_ factories: Factory...) {
  46. self.factories = factories
  47. }
  48. private func makeInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>] {
  49. return self.factories.map { $0() }
  50. }
  51. func makeGetInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>] {
  52. return self.makeInterceptors()
  53. }
  54. func makeExpandInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>] {
  55. return self.makeInterceptors()
  56. }
  57. func makeCollectInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>] {
  58. return self.makeInterceptors()
  59. }
  60. func makeUpdateInterceptors() -> [ServerInterceptor<Echo_EchoRequest, Echo_EchoResponse>] {
  61. return self.makeInterceptors()
  62. }
  63. }