ValidateAddress checks whether given address can be used with grpc dial function
(addr string)
| 768 | |
| 769 | // ValidateAddress checks whether given address can be used with grpc dial function |
| 770 | func ValidateAddress(addr string) error { |
| 771 | host, port, err := net.SplitHostPort(addr) |
| 772 | if err != nil { |
| 773 | return err |
| 774 | } |
| 775 | if p, err := strconv.Atoi(port); err != nil || p <= 0 || p >= 65536 { |
| 776 | return errors.Errorf("Invalid port: %v", p) |
| 777 | } |
| 778 | if ip := net.ParseIP(host); ip != nil { |
| 779 | return nil |
| 780 | } |
| 781 | // try to parse as hostname as per hostname RFC |
| 782 | if len(strings.Replace(host, ".", "", -1)) > 255 { |
| 783 | return errors.Errorf("Hostname should be less than or equal to 255 characters") |
| 784 | } |
| 785 | if !regExpHostName.MatchString(host) { |
| 786 | return errors.Errorf("Invalid hostname: %v", host) |
| 787 | } |
| 788 | return nil |
| 789 | } |
| 790 | |
| 791 | // RemoveDuplicates sorts the slice of strings and removes duplicates. changes the input slice. |
| 792 | // This function should be called like: someSlice = RemoveDuplicates(someSlice) |