Fix GetLocalHost testutil function for mac users (boot2docker)
This commit is contained in:
@@ -1,12 +1,27 @@
|
||||
package testutil
|
||||
|
||||
import "os"
|
||||
import (
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
)
|
||||
|
||||
var localhost = "localhost"
|
||||
|
||||
func GetLocalHost() string {
|
||||
if dockerHostVar := os.Getenv("DOCKER_HOST"); dockerHostVar != "" {
|
||||
return dockerHostVar
|
||||
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
|
||||
}
|
||||
return localhost
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user