Browse Source

pkg/types: Build a urls map from a string map

This adds a simple transformation function which is helpful when
manipulating the different etcd internal data representations.
James Shubin 9 years ago
parent
commit
029fe6bf47
1 changed files with 14 additions and 0 deletions
  1. 14 0
      pkg/types/urlsmap.go

+ 14 - 0
pkg/types/urlsmap.go

@@ -40,6 +40,20 @@ func NewURLsMap(s string) (URLsMap, error) {
 	return cl, nil
 	return cl, nil
 }
 }
 
 
+// NewURLsMapFromStringMap takes a map of strings and returns a URLsMap. The
+// string values in the map can be multiple values separated by the sep string.
+func NewURLsMapFromStringMap(m map[string]string, sep string) (URLsMap, error) {
+	var err error
+	um := URLsMap{}
+	for k, v := range m {
+		um[k], err = NewURLs(strings.Split(v, sep))
+		if err != nil {
+			return nil, err
+		}
+	}
+	return um, nil
+}
+
 // String turns URLsMap into discovery-formatted name-to-URLs sorted by name.
 // String turns URLsMap into discovery-formatted name-to-URLs sorted by name.
 func (c URLsMap) String() string {
 func (c URLsMap) String() string {
 	var pairs []string
 	var pairs []string