lib/config: Use net.JoinHostPort instead of string manipulation (#8470)

This commit is contained in:
Jakob Borg 2022-07-28 22:06:55 +02:00 committed by GitHub
parent 585fb3f49b
commit 5977868165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -590,7 +590,7 @@ func filterURLSchemePrefix(addrs []string, prefix string) []string {
// a random high port is returned.
func getFreePort(host string, ports ...int) (int, error) {
for _, port := range ports {
c, err := net.Listen("tcp", fmt.Sprintf("%s:%d", host, port))
c, err := net.Listen("tcp", net.JoinHostPort(host, strconv.Itoa(port)))
if err == nil {
c.Close()
return port, nil