2015-07-07 01:21:46 +00:00
|
|
|
package testutil
|
|
|
|
|
2015-08-03 23:16:02 +00:00
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
)
|
2015-07-07 01:21:46 +00:00
|
|
|
|
|
|
|
var localhost = "localhost"
|
|
|
|
|
|
|
|
func GetLocalHost() string {
|
|
|
|
if dockerHostVar := os.Getenv("DOCKER_HOST"); dockerHostVar != "" {
|
2015-08-03 23:16:02 +00:00
|
|
|
u, err := url.Parse(dockerHostVar)
|
|
|
|
if err != nil {
|
|
|
|
return dockerHostVar
|
|
|
|
}
|
|
|
|
|
|
|
|
// split out the ip addr from the port
|
|
|
|
host, _, err := net.SplitHostPort(u.Host)
|
|
|
|
if err != nil {
|
|
|
|
return dockerHostVar
|
|
|
|
}
|
|
|
|
|
|
|
|
return host
|
2015-07-07 01:21:46 +00:00
|
|
|
}
|
|
|
|
return localhost
|
|
|
|
}
|