Changes to L1 router to also pass the protocol it is routing.

This commit is contained in:
Jonathan Leibiusky @xetorthio
2017-08-03 11:55:53 -03:00
parent e0626f4176
commit 3906bd3b57
5 changed files with 69 additions and 25 deletions

View File

@@ -16,7 +16,7 @@ import (
"github.com/play-with-docker/play-with-docker/router"
)
func director(host string) (*net.TCPAddr, error) {
func director(protocol router.Protocol, host string) (*net.TCPAddr, error) {
info, err := router.DecodeHost(host)
if err != nil {
return nil, err
@@ -29,8 +29,15 @@ func director(host string) (*net.TCPAddr, error) {
}
if port == 0 {
// TODO: Should default depending on the protocol
port = 80
if protocol == router.ProtocolHTTP {
port = 80
} else if protocol == router.ProtocolHTTPS {
port = 443
} else if protocol == router.ProtocolSSH {
port = 22
} else if protocol == router.ProtocolDNS {
port = 53
}
}
t, err := net.ResolveTCPAddr("tcp4", fmt.Sprintf("%s:%d", info.InstanceIP, port))