Browse code

Remove unused parser functions that were replaced by go-connections/nat.

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2015/12/23 09:02:47
Showing 3 changed files
... ...
@@ -9,29 +9,6 @@ import (
9 9
 	"strings"
10 10
 )
11 11
 
12
-// PartParser parses and validates the specified string (data) using the specified template
13
-// e.g. ip:public:private -> 192.168.0.1:80:8000
14
-func PartParser(template, data string) (map[string]string, error) {
15
-	// ip:public:private
16
-	var (
17
-		templateParts = strings.Split(template, ":")
18
-		parts         = strings.Split(data, ":")
19
-		out           = make(map[string]string, len(templateParts))
20
-	)
21
-	if len(parts) != len(templateParts) {
22
-		return nil, fmt.Errorf("Invalid format to parse. %s should match template %s", data, template)
23
-	}
24
-
25
-	for i, t := range templateParts {
26
-		value := ""
27
-		if len(parts) > i {
28
-			value = parts[i]
29
-		}
30
-		out[t] = value
31
-	}
32
-	return out, nil
33
-}
34
-
35 12
 // ParseKeyValueOpt parses and validates the specified string as a key/value pair (key=value)
36 13
 func ParseKeyValueOpt(opt string) (string, string, error) {
37 14
 	parts := strings.SplitN(opt, "=", 2)
... ...
@@ -41,32 +18,6 @@ func ParseKeyValueOpt(opt string) (string, string, error) {
41 41
 	return strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1]), nil
42 42
 }
43 43
 
44
-// ParsePortRange parses and validates the specified string as a port-range (8000-9000)
45
-func ParsePortRange(ports string) (uint64, uint64, error) {
46
-	if ports == "" {
47
-		return 0, 0, fmt.Errorf("Empty string specified for ports.")
48
-	}
49
-	if !strings.Contains(ports, "-") {
50
-		start, err := strconv.ParseUint(ports, 10, 16)
51
-		end := start
52
-		return start, end, err
53
-	}
54
-
55
-	parts := strings.Split(ports, "-")
56
-	start, err := strconv.ParseUint(parts[0], 10, 16)
57
-	if err != nil {
58
-		return 0, 0, err
59
-	}
60
-	end, err := strconv.ParseUint(parts[1], 10, 16)
61
-	if err != nil {
62
-		return 0, 0, err
63
-	}
64
-	if end < start {
65
-		return 0, 0, fmt.Errorf("Invalid range specified for the Port: %s", ports)
66
-	}
67
-	return start, end, nil
68
-}
69
-
70 44
 // ParseUintList parses and validates the specified string as the value
71 45
 // found in some cgroup file (e.g. `cpuset.cpus`, `cpuset.mems`), which could be
72 46
 // one of the formats below. Note that duplicates are actually allowed in the
... ...
@@ -2,7 +2,6 @@ package parsers
2 2
 
3 3
 import (
4 4
 	"reflect"
5
-	"strings"
6 5
 	"testing"
7 6
 )
8 7
 
... ...
@@ -33,54 +32,6 @@ func TestParseKeyValueOpt(t *testing.T) {
33 33
 	}
34 34
 }
35 35
 
36
-func TestParsePortRange(t *testing.T) {
37
-	if start, end, err := ParsePortRange("8000-8080"); err != nil || start != 8000 || end != 8080 {
38
-		t.Fatalf("Error: %s or Expecting {start,end} values {8000,8080} but found {%d,%d}.", err, start, end)
39
-	}
40
-}
41
-
42
-func TestParsePortRangeEmpty(t *testing.T) {
43
-	if _, _, err := ParsePortRange(""); err == nil || err.Error() != "Empty string specified for ports." {
44
-		t.Fatalf("Expected error 'Empty string specified for ports.', got %v", err)
45
-	}
46
-}
47
-
48
-func TestParsePortRangeWithNoRange(t *testing.T) {
49
-	start, end, err := ParsePortRange("8080")
50
-	if err != nil {
51
-		t.Fatal(err)
52
-	}
53
-	if start != 8080 || end != 8080 {
54
-		t.Fatalf("Expected start and end to be the same and equal to 8080, but were %v and %v", start, end)
55
-	}
56
-}
57
-
58
-func TestParsePortRangeIncorrectRange(t *testing.T) {
59
-	if _, _, err := ParsePortRange("9000-8080"); err == nil || !strings.Contains(err.Error(), "Invalid range specified for the Port") {
60
-		t.Fatalf("Expecting error 'Invalid range specified for the Port' but received %s.", err)
61
-	}
62
-}
63
-
64
-func TestParsePortRangeIncorrectEndRange(t *testing.T) {
65
-	if _, _, err := ParsePortRange("8000-a"); err == nil || !strings.Contains(err.Error(), "invalid syntax") {
66
-		t.Fatalf("Expecting error 'Invalid range specified for the Port' but received %s.", err)
67
-	}
68
-
69
-	if _, _, err := ParsePortRange("8000-30a"); err == nil || !strings.Contains(err.Error(), "invalid syntax") {
70
-		t.Fatalf("Expecting error 'Invalid range specified for the Port' but received %s.", err)
71
-	}
72
-}
73
-
74
-func TestParsePortRangeIncorrectStartRange(t *testing.T) {
75
-	if _, _, err := ParsePortRange("a-8000"); err == nil || !strings.Contains(err.Error(), "invalid syntax") {
76
-		t.Fatalf("Expecting error 'Invalid range specified for the Port' but received %s.", err)
77
-	}
78
-
79
-	if _, _, err := ParsePortRange("30a-8000"); err == nil || !strings.Contains(err.Error(), "invalid syntax") {
80
-		t.Fatalf("Expecting error 'Invalid range specified for the Port' but received %s.", err)
81
-	}
82
-}
83
-
84 36
 func TestParseUintList(t *testing.T) {
85 37
 	valids := map[string]map[int]bool{
86 38
 		"":             {},
... ...
@@ -11,7 +11,6 @@ import (
11 11
 	"github.com/docker/docker/opts"
12 12
 	flag "github.com/docker/docker/pkg/mflag"
13 13
 	"github.com/docker/docker/pkg/mount"
14
-	"github.com/docker/docker/pkg/parsers"
15 14
 	"github.com/docker/docker/pkg/signal"
16 15
 	"github.com/docker/docker/volume"
17 16
 	"github.com/docker/go-connections/nat"
... ...
@@ -285,7 +284,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*container.Config, *container.Host
285 285
 		proto, port := nat.SplitProtoPort(e)
286 286
 		//parse the start and end port and create a sequence of ports to expose
287 287
 		//if expose a port, the start and end port are the same
288
-		start, end, err := parsers.ParsePortRange(port)
288
+		start, end, err := nat.ParsePortRange(port)
289 289
 		if err != nil {
290 290
 			return nil, nil, cmd, fmt.Errorf("Invalid range format for --expose: %s, error: %s", e, err)
291 291
 		}