ServiceDescriptor.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright 2024, 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. /// A description of a service.
  17. public struct ServiceDescriptor: Sendable, Hashable {
  18. /// The name of the package the service belongs to. For example, "helloworld".
  19. /// An empty string means that the service does not belong to any package.
  20. public var package: String
  21. /// The name of the service. For example, "Greeter".
  22. public var service: String
  23. /// The fully qualified service name in the format:
  24. /// - "package.service": if a package name is specified. For example, "helloworld.Greeter".
  25. /// - "service": if a package name is not specified. For example, "Greeter".
  26. public var fullyQualifiedService: String {
  27. if self.package.isEmpty {
  28. return self.service
  29. }
  30. return "\(self.package).\(self.service)"
  31. }
  32. /// - Parameters:
  33. /// - package: The name of the package the service belongs to. For example, "helloworld".
  34. /// An empty string means that the service does not belong to any package.
  35. /// - service: The name of the service. For example, "Greeter".
  36. public init(package: String, service: String) {
  37. self.package = package
  38. self.service = service
  39. }
  40. }