23 lines
427 B
Go
23 lines
427 B
Go
package net
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
func HostPort(addr string, port any) string {
|
|
host := addr
|
|
if strings.Count(addr, ":") > 0 {
|
|
host = fmt.Sprintf("[%s]", addr)
|
|
}
|
|
// when port is blank or 0, host is a queue name
|
|
if v, ok := port.(string); ok && v == "" {
|
|
return host
|
|
} else if v, ok := port.(int); ok && v == 0 && net.ParseIP(host) == nil {
|
|
return host
|
|
}
|
|
|
|
return fmt.Sprintf("%s:%v", host, port)
|
|
}
|