Explorar o código

Allow binding to a socket address via server builder (#1686)

Motivation:

Users can bind to a socket address if they use the server config but not
the builder.

Modifications:

- Add API to connect to a socket address or bind target via the server
  builder API

Result:

More convenient APIs
George Barnett %!s(int64=2) %!d(string=hai) anos
pai
achega
fdf0a8175e
Modificáronse 1 ficheiros con 12 adicións e 0 borrados
  1. 12 0
      Sources/GRPC/ServerBuilder.swift

+ 12 - 0
Sources/GRPC/ServerBuilder.swift

@@ -62,11 +62,23 @@ extension Server {
       return Server.start(configuration: self.configuration)
     }
 
+    public func bind(to socketAddress: SocketAddress) -> EventLoopFuture<Server> {
+      self.configuration.target = .socketAddress(socketAddress)
+      self.configuration.tlsConfiguration = self.maybeTLS
+      return Server.start(configuration: self.configuration)
+    }
+
     public func bind(vsockAddress: VsockAddress) -> EventLoopFuture<Server> {
       self.configuration.target = .vsockAddress(vsockAddress)
       self.configuration.tlsConfiguration = self.maybeTLS
       return Server.start(configuration: self.configuration)
     }
+
+    public func bind(to target: BindTarget) -> EventLoopFuture<Server> {
+      self.configuration.target = target
+      self.configuration.tlsConfiguration = self.maybeTLS
+      return Server.start(configuration: self.configuration)
+    }
   }
 }