[Groonga-commit] groonga/grnci at e1042dc [master] Update v2.

Back to archive index

Susumu Yata null+****@clear*****
Wed May 17 19:23:04 JST 2017


Susumu Yata	2017-05-17 19:23:04 +0900 (Wed, 17 May 2017)

  New Revision: e1042dc0c465703dde20bb170b701d47f13feff6
  https://github.com/groonga/grnci/commit/e1042dc0c465703dde20bb170b701d47f13feff6

  Message:
    Update v2.

  Modified files:
    v2/address.go

  Modified: v2/address.go (+41 -35)
===================================================================
--- v2/address.go    2017-05-16 18:27:57 +0900 (cfa5634)
+++ v2/address.go    2017-05-17 19:23:04 +0900 (024a332)
@@ -133,6 +133,45 @@ func (a *Address) fill() error {
 	return nil
 }
 
+// parseHostPort parses a host and a port in an address.
+func (a *Address) parseHostPort(s string) error {
+	if s == "" {
+		return nil
+	}
+	portStr := ""
+	if s[0] == '[' {
+		i := strings.IndexByte(s, ']')
+		if i == -1 {
+			return fmt.Errorf("missing ']': s = %s", s)
+		}
+		a.Host = s[:i+1]
+		rest := s[i+1:]
+		if rest == "" {
+			return nil
+		}
+		if rest[0] != ':' {
+			return fmt.Errorf("missing ':' after ']': s = %s", s)
+		}
+		portStr = rest[1:]
+	} else {
+		i := strings.LastIndexByte(s, ':')
+		if i == -1 {
+			a.Host = s
+			return nil
+		}
+		a.Host = s[:i]
+		portStr = s[i+1:]
+	}
+	if portStr != "" {
+		port, err := net.LookupPort("tcp", portStr)
+		if err != nil {
+			return fmt.Errorf("net.LookupPort failed: %v", err)
+		}
+		a.Port = port
+	}
+	return nil
+}
+
 // ParseAddress parses an address.
 // The expected address format is
 // [scheme://][username[:password]@]host[:port][path][?query][#fragment].
@@ -165,42 +204,9 @@ func ParseAddress(s string) (*Address, error) {
 		}
 		s = s[i+1:]
 	}
-	if s == "" {
-		return a, nil
-	}
-
-	portStr := ""
-	if s[0] == '[' {
-		i := strings.IndexByte(s, ']')
-		if i == -1 {
-			return nil, fmt.Errorf("missing ']': s = %s", s)
-		}
-		a.Host = s[:i+1]
-		rest := s[i+1:]
-		if rest == "" {
-			return a, nil
-		}
-		if rest[0] != ':' {
-			return nil, fmt.Errorf("missing ':' after ']': s = %s", s)
-		}
-		portStr = rest[1:]
-	} else {
-		i := strings.LastIndexByte(s, ':')
-		if i == -1 {
-			a.Host = s
-			return a, nil
-		}
-		a.Host = s[:i]
-		portStr = s[i+1:]
-	}
-	if portStr != "" {
-		port, err := net.LookupPort("tcp", portStr)
-		if err != nil {
-			return nil, fmt.Errorf("net.LookupPort failed: %v", err)
-		}
-		a.Port = port
+	if err := a.parseHostPort(s); err != nil {
+		return nil, err
 	}
-
 	if err := a.fill(); err != nil {
 		return nil, err
 	}
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index