Browse code

Update Version to not use string anymore

Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes <guillaume@charmes.net> (github: creack)

Guillaume J. Charmes authored on 2014/04/02 07:46:52
Showing 4 changed files
... ...
@@ -3,15 +3,16 @@ package api
3 3
 import (
4 4
 	"fmt"
5 5
 	"github.com/dotcloud/docker/engine"
6
+	"github.com/dotcloud/docker/pkg/version"
6 7
 	"github.com/dotcloud/docker/utils"
7 8
 	"mime"
8 9
 	"strings"
9 10
 )
10 11
 
11 12
 const (
12
-	APIVERSION        = "1.10"
13
-	DEFAULTHTTPHOST   = "127.0.0.1"
14
-	DEFAULTUNIXSOCKET = "/var/run/docker.sock"
13
+	APIVERSION        version.Version = "1.10"
14
+	DEFAULTHTTPHOST                   = "127.0.0.1"
15
+	DEFAULTUNIXSOCKET                 = "/var/run/docker.sock"
15 16
 )
16 17
 
17 18
 func ValidateHost(val string) (string, error) {
... ...
@@ -940,7 +940,7 @@ func makeHttpHandler(eng *engine.Engine, logging bool, localMethod string, local
940 940
 
941 941
 		if strings.Contains(r.Header.Get("User-Agent"), "Docker-Client/") {
942 942
 			userAgent := strings.Split(r.Header.Get("User-Agent"), "/")
943
-			if len(userAgent) == 2 && !dockerVersion.Equal(userAgent[1]) {
943
+			if len(userAgent) == 2 && !dockerVersion.Equal(version.Version(userAgent[1])) {
944 944
 				utils.Debugf("Warning: client and server don't have the same version (client: %s, server: %s)", userAgent[1], dockerVersion)
945 945
 			}
946 946
 		}
... ...
@@ -7,10 +7,10 @@ import (
7 7
 
8 8
 type Version string
9 9
 
10
-func (me Version) compareTo(other string) int {
10
+func (me Version) compareTo(other Version) int {
11 11
 	var (
12 12
 		meTab    = strings.Split(string(me), ".")
13
-		otherTab = strings.Split(other, ".")
13
+		otherTab = strings.Split(string(other), ".")
14 14
 	)
15 15
 	for i, s := range meTab {
16 16
 		var meInt, otherInt int
... ...
@@ -31,22 +31,22 @@ func (me Version) compareTo(other string) int {
31 31
 	return 0
32 32
 }
33 33
 
34
-func (me Version) LessThan(other string) bool {
34
+func (me Version) LessThan(other Version) bool {
35 35
 	return me.compareTo(other) == -1
36 36
 }
37 37
 
38
-func (me Version) LessThanOrEqualTo(other string) bool {
38
+func (me Version) LessThanOrEqualTo(other Version) bool {
39 39
 	return me.compareTo(other) <= 0
40 40
 }
41 41
 
42
-func (me Version) GreaterThan(other string) bool {
42
+func (me Version) GreaterThan(other Version) bool {
43 43
 	return me.compareTo(other) == 1
44 44
 }
45 45
 
46
-func (me Version) GreaterThanOrEqualTo(other string) bool {
46
+func (me Version) GreaterThanOrEqualTo(other Version) bool {
47 47
 	return me.compareTo(other) >= 0
48 48
 }
49 49
 
50
-func (me Version) Equal(other string) bool {
50
+func (me Version) Equal(other Version) bool {
51 51
 	return me.compareTo(other) == 0
52 52
 }
... ...
@@ -5,7 +5,7 @@ import (
5 5
 )
6 6
 
7 7
 func assertVersion(t *testing.T, a, b string, result int) {
8
-	if r := Version(a).compareTo(b); r != result {
8
+	if r := Version(a).compareTo(Version(b)); r != result {
9 9
 		t.Fatalf("Unexpected version comparison result. Found %d, expected %d", r, result)
10 10
 	}
11 11
 }