Merge pull request #4961 from creack/update_version_pkg

Update Version to not use string anymore
This commit is contained in:
Victor Vieux 2014-04-01 18:37:25 -07:00
Родитель b4c8232b95 3ee37f547f
Коммит 93bb208164
4 изменённых файлов: 13 добавлений и 12 удалений

Просмотреть файл

@ -3,13 +3,14 @@ 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"
APIVERSION version.Version = "1.10"
DEFAULTHTTPHOST = "127.0.0.1"
DEFAULTUNIXSOCKET = "/var/run/docker.sock"
)

Просмотреть файл

@ -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)
}
}

Просмотреть файл

@ -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
}

Просмотреть файл

@ -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)
}
}