github.com/xmidt-org/webpa-common@v1.11.9/xhttp/url.go (about) 1 package xhttp 2 3 import ( 4 "fmt" 5 "net/url" 6 ) 7 8 // ApplyURLParser applies a given URL parser, such as url.Parse or url.ParseRequestURI, to zero or more strings. 9 // The resulting slice is ordered the same as the values. Any error halts parsing of subsequent values. 10 func ApplyURLParser(parser func(string) (*url.URL, error), values ...string) ([]*url.URL, error) { 11 urls := make([]*url.URL, len(values)) 12 for i, v := range values { 13 u, err := parser(v) 14 if err != nil { 15 return nil, fmt.Errorf("Unable to parse URL '%s': %s", v, err) 16 } 17 18 urls[i] = u 19 } 20 21 return urls, nil 22 }