package net import ( "net" "strconv" ) // TrulyAddr returns the truly address of the listener. func TrulyAddr(addr string, l net.Listener) string { host, port, err := net.SplitHostPort(addr) if err != nil && l == nil { return "" } if l != nil { if taddr, ok := l.Addr().(*net.TCPAddr); ok { port = strconv.Itoa(taddr.Port) } } if len(host) > 0 && (host != "0.0.0.0" && host != "[::]" && host != "::") { return net.JoinHostPort(host, port) } host = LocalIP() return net.JoinHostPort(host, port) }