1
0

util.go 585 B

123456789101112131415161718192021
  1. package upstream
  2. // formatSocketAddress formats a host:port combination into a proper socket address
  3. // For IPv6 addresses, it adds brackets around the host if they're not already present
  4. func formatSocketAddress(host, port string) string {
  5. // Reuse the logic from service package
  6. if len(host) > 0 && host[0] != '[' && containsColon(host) {
  7. return "[" + host + "]:" + port
  8. }
  9. return host + ":" + port
  10. }
  11. // containsColon checks if string contains a colon
  12. func containsColon(s string) bool {
  13. for i := 0; i < len(s); i++ {
  14. if s[i] == ':' {
  15. return true
  16. }
  17. }
  18. return false
  19. }