MCPcopy
hub / github.com/dgraph-io/dgraph / ValidateAddress

Function ValidateAddress

x/x.go:770–789  ·  view source on GitHub ↗

ValidateAddress checks whether given address can be used with grpc dial function

(addr string)

Source from the content-addressed store, hash-verified

768
769// ValidateAddress checks whether given address can be used with grpc dial function
770func 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)

Callers 2

StartRaftNodesFunction · 0.92
TestValidateAddressFunction · 0.85

Calls 1

ErrorfMethod · 0.45

Tested by 1

TestValidateAddressFunction · 0.68