@@ -37,9 +37,14 @@ public class Channel {
3737 /// Initializes a gRPC channel
3838 ///
3939 /// - Parameter address: the address of the server to be called
40- public init ( address: String ) {
40+ /// - Parameter secure: if true, use TLS
41+ public init ( address: String , secure: Bool = false ) {
4142 self . host = address
42- underlyingChannel = cgrpc_channel_create ( address)
43+ if secure {
44+ underlyingChannel = cgrpc_channel_create_secure ( address, roots_pem ( ) , nil )
45+ } else {
46+ underlyingChannel = cgrpc_channel_create ( address)
47+ }
4348 completionQueue = CompletionQueue ( underlyingCompletionQueue: cgrpc_channel_completion_queue ( underlyingChannel) )
4449 completionQueue. name = " Client " // only for debugging
4550 self . completionQueue. run ( ) // start a loop that watches the channel's completion queue
@@ -48,13 +53,11 @@ public class Channel {
4853 /// Initializes a gRPC channel
4954 ///
5055 /// - Parameter address: the address of the server to be called
51- public init ( address: String , certificates: String ? , host: String ? ) {
56+ /// - Parameter certificates: a PEM representation of certificates to use
57+ /// - Parameter host: an optional hostname override
58+ public init ( address: String , certificates: String , host: String ? ) {
5259 self . host = address
53- if let certificates = certificates {
54- underlyingChannel = cgrpc_channel_create_secure ( address, certificates, host)
55- } else {
56- underlyingChannel = cgrpc_channel_create_secure ( address, roots_pem ( ) , host)
57- }
60+ underlyingChannel = cgrpc_channel_create_secure ( address, certificates, host)
5861 completionQueue = CompletionQueue ( underlyingCompletionQueue: cgrpc_channel_completion_queue ( underlyingChannel) )
5962 completionQueue. name = " Client " // only for debugging
6063 self . completionQueue. run ( ) // start a loop that watches the channel's completion queue
0 commit comments