github.com/searKing/golang/go@v1.2.117/net/url/port.go (about)

     1  // Copyright 2020 The searKing Author. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package url
     6  
     7  import "strings"
     8  
     9  // Given a string of the form "host", "host:port", or "[ipv6::address]:port",
    10  // return true if the string includes a port.
    11  func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") }
    12  
    13  // removeEmptyPort strips the empty port in ":port" to ""
    14  // as mandated by RFC 3986 Section 6.2.3.
    15  func removeEmptyPort(host string) string {
    16  	if hasPort(host) {
    17  		return strings.TrimSuffix(host, ":")
    18  	}
    19  	return host
    20  }