Browse Source

Merge pull request #202 from rebello95/channel-specification

Support for Channel specification on ServiceClient
Tim Burks 7 years ago
parent
commit
f10a8ec722

+ 2 - 0
Sources/SwiftGRPC/Core/Channel.swift

@@ -41,6 +41,7 @@ public class Channel {
   /// - Parameter address: the address of the server to be called
   /// - Parameter secure: if true, use TLS
   public init(address: String, secure: Bool = true) {
+    gRPC.initialize()
     host = address
     if secure {
       underlyingChannel = cgrpc_channel_create_secure(address, roots_pem(), nil)
@@ -58,6 +59,7 @@ public class Channel {
   /// - Parameter certificates: a PEM representation of certificates to use
   /// - Parameter host: an optional hostname override
   public init(address: String, certificates: String, host: String?) {
+    gRPC.initialize()
     self.host = address
     underlyingChannel = cgrpc_channel_create_secure(address, certificates, host)
     completionQueue = CompletionQueue(

+ 7 - 0
Sources/SwiftGRPC/Runtime/ServiceClient.swift

@@ -55,6 +55,13 @@ open class ServiceClientBase: ServiceClient {
     metadata = Metadata()
   }
 
+  /// Create a client using a pre-defined channel.
+  public init(channel: Channel) {
+    gRPC.initialize()
+    self.channel = channel
+    self.metadata = Metadata()
+  }
+
   /// Create a client that makes secure connections with a custom certificate and (optional) hostname.
   public init(address: String, certificates: String, host: String?) {
     gRPC.initialize()