Browse Source

Use optional binding when initializing a Channel with certificates.

Tim Burks 9 years ago
parent
commit
258478fa3a
1 changed files with 3 additions and 3 deletions
  1. 3 3
      Sources/gRPC/Channel.swift

+ 3 - 3
Sources/gRPC/Channel.swift

@@ -67,14 +67,14 @@ public class Channel {
   /// - Parameter address: the address of the server to be called
   /// - Parameter address: the address of the server to be called
   public init(address: String, certificates: String?, host: String?) {
   public init(address: String, certificates: String?, host: String?) {
     self.host = address
     self.host = address
-    if certificates == nil {
+    if let certificates = certificates {
+      underlyingChannel = cgrpc_channel_create_secure(address, certificates, host)
+    } else {
       let bundle = Bundle(for: Channel.self)
       let bundle = Bundle(for: Channel.self)
       let url = bundle.url(forResource: "roots", withExtension: "pem")!
       let url = bundle.url(forResource: "roots", withExtension: "pem")!
       let data = try! Data(contentsOf: url)
       let data = try! Data(contentsOf: url)
       let s = String(data: data, encoding: .ascii)
       let s = String(data: data, encoding: .ascii)
       underlyingChannel = cgrpc_channel_create_secure(address, s, host)
       underlyingChannel = cgrpc_channel_create_secure(address, s, host)
-    } else {
-      underlyingChannel = cgrpc_channel_create_secure(address, certificates, host)
     }
     }
     completionQueue = CompletionQueue(underlyingCompletionQueue:cgrpc_channel_completion_queue(underlyingChannel))
     completionQueue = CompletionQueue(underlyingCompletionQueue:cgrpc_channel_completion_queue(underlyingChannel))
     completionQueue.name = "Client" // only for debugging
     completionQueue.name = "Client" // only for debugging