HostnamesMatch returns true if the hostnames are equal, disregarding capitalization, extra leading or trailing periods, and ports.
(a, b string)
| 208 | // HostnamesMatch returns true if the hostnames are equal, disregarding |
| 209 | // capitalization, extra leading or trailing periods, and ports. |
| 210 | func HostnamesMatch(a, b string) bool { |
| 211 | a = strings.Trim(a, ".") |
| 212 | b = strings.Trim(b, ".") |
| 213 | |
| 214 | aHost, _, err := net.SplitHostPort(a) |
| 215 | if err != nil { |
| 216 | aHost = a |
| 217 | } |
| 218 | bHost, _, err := net.SplitHostPort(b) |
| 219 | if err != nil { |
| 220 | bHost = b |
| 221 | } |
| 222 | |
| 223 | return strings.EqualFold(aHost, bHost) |
| 224 | } |
| 225 | |
| 226 | // CompileHostnamePattern compiles a hostname pattern into a regular expression. |
| 227 | // A hostname pattern is a string that may contain a single wildcard character |