github.com/michael-k/docker@v1.7.0-rc2/pkg/proxy/proxy.go (about)

     1  package proxy
     2  
     3  import (
     4  	"fmt"
     5  	"net"
     6  )
     7  
     8  type Proxy interface {
     9  	// Start forwarding traffic back and forth the front and back-end
    10  	// addresses.
    11  	Run()
    12  	// Stop forwarding traffic and close both ends of the Proxy.
    13  	Close()
    14  	// Return the address on which the proxy is listening.
    15  	FrontendAddr() net.Addr
    16  	// Return the proxied address.
    17  	BackendAddr() net.Addr
    18  }
    19  
    20  func NewProxy(frontendAddr, backendAddr net.Addr) (Proxy, error) {
    21  	switch frontendAddr.(type) {
    22  	case *net.UDPAddr:
    23  		return NewUDPProxy(frontendAddr.(*net.UDPAddr), backendAddr.(*net.UDPAddr))
    24  	case *net.TCPAddr:
    25  		return NewTCPProxy(frontendAddr.(*net.TCPAddr), backendAddr.(*net.TCPAddr))
    26  	default:
    27  		panic(fmt.Errorf("Unsupported protocol"))
    28  	}
    29  }