hasExplicitPort checks if the given host string (or host:port) has an explicit port defined. It handles IPv6 addresses (e.g. [::1]:8080) correctly.
(hostStr string)
| 3802 | // hasExplicitPort checks if the given host string (or host:port) |
| 3803 | // has an explicit port defined. It handles IPv6 addresses (e.g. [::1]:8080) correctly. |
| 3804 | func hasExplicitPort(hostStr string) bool { |
| 3805 | // Basic check: if no colon, definitely no port (unless it's a bare IPv6, but that doesn't have a port either) |
| 3806 | if !strings.Contains(hostStr, ":") { |
| 3807 | return false |
| 3808 | } |
| 3809 | |
| 3810 | // Attempt to split host/port |
| 3811 | // net.SplitHostPort handles IPv6 addresses enclosed in brackets [::1]:8080 |
| 3812 | _, port, err := net.SplitHostPort(hostStr) |
| 3813 | if err != nil { |
| 3814 | return false |
| 3815 | } |
| 3816 | |
| 3817 | // If a port is found, verify it is numeric |
| 3818 | if port != "" { |
| 3819 | if _, err := strconv.Atoi(port); err == nil { |
| 3820 | return true |
| 3821 | } |
| 3822 | } |
| 3823 | |
| 3824 | return false |
| 3825 | } |
| 3826 | |
| 3827 | // ResolveTestTarget determines the final target (URL for HTTP, Authority for gRPC) |
| 3828 | // by applying replacement logic and precedence rules. |
no outgoing calls