9 // PartParser parses and validates the specified string (data) using the specified template
10 // e.g. ip:public:private -> 192.168.0.1:80:8000
11 // DEPRECATED: do not use, this function may be removed in a future version
12 func PartParser(template, data string) (map[string]string, error) {
15 templateParts = strings.Split(template, ":")
16 parts = strings.Split(data, ":")
17 out = make(map[string]string, len(templateParts))
19 if len(parts) != len(templateParts) {
20 return nil, fmt.Errorf("Invalid format to parse. %s should match template %s", data, template)
23 for i, t := range templateParts {
33 // ParsePortRange parses and validates the specified string as a port-range (8000-9000)
34 func ParsePortRange(ports string) (uint64, uint64, error) {
36 return 0, 0, fmt.Errorf("Empty string specified for ports.")
38 if !strings.Contains(ports, "-") {
39 start, err := strconv.ParseUint(ports, 10, 16)
41 return start, end, err
44 parts := strings.Split(ports, "-")
45 start, err := strconv.ParseUint(parts[0], 10, 16)
49 end, err := strconv.ParseUint(parts[1], 10, 16)
54 return 0, 0, fmt.Errorf("Invalid range specified for the Port: %s", ports)
56 return start, end, nil