1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-11-24 08:02:32 +02:00

Merge pull request #99 from xujinzheng/master

improve self-signed host list
This commit is contained in:
Asim Aslam 2016-06-06 14:02:16 +01:00
commit 05596cfae4

View File

@ -409,7 +409,16 @@ func (h *httpTransport) Listen(addr string, opts ...ListenOption) (Listener, err
fn := func(addr string) (net.Listener, error) { fn := func(addr string) (net.Listener, error) {
if config == nil { if config == nil {
cert, err := mls.Certificate(addr) hosts := []string{addr}
if h, _, e := net.SplitHostPort(addr); e == nil {
if len(h) == 0 {
hosts = getIPAddrs()
} else {
hosts = []string{h}
}
}
cert, err := mls.Certificate(hosts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -447,3 +456,41 @@ func newHTTPTransport(opts ...Option) *httpTransport {
} }
return &httpTransport{opts: options} return &httpTransport{opts: options}
} }
func getIPAddrs() []string {
ifaces, err := net.Interfaces()
if err != nil {
return nil
}
var ipAddrs []string
for _, i := range ifaces {
addrs, err := i.Addrs()
if err != nil {
continue
}
for _, addr := range addrs {
var ip net.IP
switch v := addr.(type) {
case *net.IPNet:
ip = v.IP
case *net.IPAddr:
ip = v.IP
}
if ip == nil {
continue
}
ip = ip.To4()
if ip == nil {
continue
}
ipAddrs = append(ipAddrs, ip.String())
}
}
return ipAddrs
}