From 3ee37f547f4685ab88bfc39517cc18c1911451e5 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 1 Apr 2014 15:46:52 -0700 Subject: [PATCH] Update Version to not use string anymore Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes (github: creack) --- api/common.go | 7 ++++--- api/server/server.go | 2 +- pkg/version/version.go | 14 +++++++------- pkg/version/version_test.go | 2 +- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/api/common.go b/api/common.go index 7273e5c56d..44bd901379 100644 --- a/api/common.go +++ b/api/common.go @@ -3,15 +3,16 @@ package api import ( "fmt" "github.com/dotcloud/docker/engine" + "github.com/dotcloud/docker/pkg/version" "github.com/dotcloud/docker/utils" "mime" "strings" ) const ( - APIVERSION = "1.10" - DEFAULTHTTPHOST = "127.0.0.1" - DEFAULTUNIXSOCKET = "/var/run/docker.sock" + APIVERSION version.Version = "1.10" + DEFAULTHTTPHOST = "127.0.0.1" + DEFAULTUNIXSOCKET = "/var/run/docker.sock" ) func ValidateHost(val string) (string, error) { diff --git a/api/server/server.go b/api/server/server.go index 5597d8b92c..93dd2094b6 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -940,7 +940,7 @@ func makeHttpHandler(eng *engine.Engine, logging bool, localMethod string, local if strings.Contains(r.Header.Get("User-Agent"), "Docker-Client/") { userAgent := strings.Split(r.Header.Get("User-Agent"), "/") - if len(userAgent) == 2 && !dockerVersion.Equal(userAgent[1]) { + if len(userAgent) == 2 && !dockerVersion.Equal(version.Version(userAgent[1])) { utils.Debugf("Warning: client and server don't have the same version (client: %s, server: %s)", userAgent[1], dockerVersion) } } diff --git a/pkg/version/version.go b/pkg/version/version.go index 3721d64aa8..5ff9d2ed2a 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -7,10 +7,10 @@ import ( type Version string -func (me Version) compareTo(other string) int { +func (me Version) compareTo(other Version) int { var ( meTab = strings.Split(string(me), ".") - otherTab = strings.Split(other, ".") + otherTab = strings.Split(string(other), ".") ) for i, s := range meTab { var meInt, otherInt int @@ -31,22 +31,22 @@ func (me Version) compareTo(other string) int { return 0 } -func (me Version) LessThan(other string) bool { +func (me Version) LessThan(other Version) bool { return me.compareTo(other) == -1 } -func (me Version) LessThanOrEqualTo(other string) bool { +func (me Version) LessThanOrEqualTo(other Version) bool { return me.compareTo(other) <= 0 } -func (me Version) GreaterThan(other string) bool { +func (me Version) GreaterThan(other Version) bool { return me.compareTo(other) == 1 } -func (me Version) GreaterThanOrEqualTo(other string) bool { +func (me Version) GreaterThanOrEqualTo(other Version) bool { return me.compareTo(other) >= 0 } -func (me Version) Equal(other string) bool { +func (me Version) Equal(other Version) bool { return me.compareTo(other) == 0 } diff --git a/pkg/version/version_test.go b/pkg/version/version_test.go index 4bebd0c434..27c0536c2f 100644 --- a/pkg/version/version_test.go +++ b/pkg/version/version_test.go @@ -5,7 +5,7 @@ import ( ) func assertVersion(t *testing.T, a, b string, result int) { - if r := Version(a).compareTo(b); r != result { + if r := Version(a).compareTo(Version(b)); r != result { t.Fatalf("Unexpected version comparison result. Found %d, expected %d", r, result) } }