diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/server.go | 17 | 
1 files changed, 17 insertions, 0 deletions
| diff --git a/internal/server.go b/internal/server.go index 3efdf6e..e3fbfb2 100644 --- a/internal/server.go +++ b/internal/server.go @@ -3,6 +3,7 @@ package internal  import (  	"context"  	"net" +	"strings"  	"sync"  ) @@ -126,3 +127,19 @@ func (s *Server) propagateClose() {  		_ = s.Listener.Close()  	}()  } + +// JoinDefaultPort appends ":<port>" iff the address does not already contain a port. +func JoinDefaultPort(address string, port string) string { +	if address[0] == '[' { +		hend := strings.LastIndexByte(address, ']') +		if len(address) > hend+1 && address[hend+1] == ':' { +			return address +		} +		return net.JoinHostPort(address[1:hend], port) +	} + +	if strings.Contains(address, ":") { +		return address +	} +	return net.JoinHostPort(address, port) +} | 
