Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace 'ConnectionTarget' enum with a struct #861

Merged
merged 1 commit into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions Sources/GRPC/ClientConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,35 @@ extension ClientConnection: GRPCChannel {
// MARK: - Configuration structures

/// A target to connect to.
public enum ConnectionTarget {
public struct ConnectionTarget {
internal enum Wrapped {
case hostAndPort(String, Int)
case unixDomainSocket(String)
case socketAddress(SocketAddress)
}

internal var wrapped: Wrapped
private init(_ wrapped: Wrapped) {
self.wrapped = wrapped
}

/// The host and port.
case hostAndPort(String, Int)
public static func hostAndPort(_ host: String, _ port: Int) -> ConnectionTarget {
return ConnectionTarget(.hostAndPort(host, port))
}

/// The path of a Unix domain socket.
case unixDomainSocket(String)
public static func unixDomainSocket(_ path: String) -> ConnectionTarget {
return ConnectionTarget(.unixDomainSocket(path))
}

/// A NIO socket address.
case socketAddress(SocketAddress)
public static func socketAddress(_ address: SocketAddress) -> ConnectionTarget {
return ConnectionTarget(.socketAddress(address))
}

var host: String {
switch self {
switch self.wrapped {
case .hostAndPort(let host, _):
return host
case .socketAddress(.v4(let address)):
Expand Down Expand Up @@ -335,7 +354,7 @@ extension ClientBootstrapProtocol {
///
/// - Parameter target: The target to connect to.
func connect(to target: ConnectionTarget) -> EventLoopFuture<Channel> {
switch target {
switch target.wrapped {
case .hostAndPort(let host, let port):
return self.connect(host: host, port: port)

Expand Down
2 changes: 1 addition & 1 deletion Sources/GRPC/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fileprivate extension Channel {

fileprivate extension ServerBootstrapProtocol {
func bind(to target: BindTarget) -> EventLoopFuture<Channel> {
switch target {
switch target.wrapped {
case .hostAndPort(let host, let port):
return self.bind(host: host, port: port)

Expand Down