From 87a4d735565383477f5f6a7e2bcd156e011d56d8 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Thu, 21 Jul 2016 16:33:49 +0200 Subject: [PATCH] =?UTF-8?q?Move=20version.go=20in=20its=20own=20package?= =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … making it possible to use in other packages ; and thus in the User-Agent header for the docker client. Also removing the dockerverion hack as it's not required anymore. Signed-off-by: Vincent Demeester --- generate.go | 3 --- provider/docker.go | 4 ++-- script/binary | 2 +- script/dockerversion | 12 ------------ traefik.go | 26 ++++++++++++++------------ version.go => version/version.go | 2 +- 6 files changed, 18 insertions(+), 31 deletions(-) delete mode 100644 script/dockerversion rename version.go => version/version.go (94%) diff --git a/generate.go b/generate.go index a9602710c..f922492f2 100644 --- a/generate.go +++ b/generate.go @@ -6,7 +6,4 @@ Copyright //go:generate mkdir -p static //go:generate go-bindata -pkg autogen -o autogen/gen.go ./static/... ./templates/... -//go:generate mkdir -p vendor/github.com/docker/docker/autogen/dockerversion -//go:generate cp script/dockerversion vendor/github.com/docker/docker/autogen/dockerversion/dockerversion.go - package main diff --git a/provider/docker.go b/provider/docker.go index 71897f56b..8ed7a2754 100644 --- a/provider/docker.go +++ b/provider/docker.go @@ -15,6 +15,7 @@ import ( "github.com/cenkalti/backoff" "github.com/containous/traefik/safe" "github.com/containous/traefik/types" + "github.com/containous/traefik/version" "github.com/docker/engine-api/client" dockertypes "github.com/docker/engine-api/types" eventtypes "github.com/docker/engine-api/types/events" @@ -38,8 +39,7 @@ type Docker struct { func (provider *Docker) createClient() (client.APIClient, error) { var httpClient *http.Client httpHeaders := map[string]string{ - // FIXME(vdemeester) use version here O:) - "User-Agent": "Traefik", + "User-Agent": "Traefik " + version.Version, } if provider.TLS != nil { config, err := provider.TLS.CreateTLSConfig() diff --git a/script/binary b/script/binary index 9ed9225a5..b89b525a9 100755 --- a/script/binary +++ b/script/binary @@ -26,4 +26,4 @@ if [ -z "$DATE" ]; then fi # Build binaries -CGO_ENABLED=0 GOGC=off go build $FLAGS -ldflags "-s -w -X main.Version=$VERSION -X main.Codename=$CODENAME -X main.BuildDate=$DATE" -a -installsuffix nocgo -o dist/traefik . +CGO_ENABLED=0 GOGC=off go build $FLAGS -ldflags "-s -w -X version.Version=$VERSION -X version.Codename=$CODENAME -X version.BuildDate=$DATE" -a -installsuffix nocgo -o dist/traefik . diff --git a/script/dockerversion b/script/dockerversion deleted file mode 100644 index d2ea51254..000000000 --- a/script/dockerversion +++ /dev/null @@ -1,12 +0,0 @@ -// AUTOGENERATED FILE; see /go/src/github.com/docker/docker/hack/make/.go-autogen -package dockerversion - -var ( - GITCOMMIT string = "traefik-import" - VERSION string = "traefik-import" - BUILDTIME string = "traefik-import" - - IAMSTATIC string = "traefik-import" - INITSHA1 string = "traefik-import" - INITPATH string = "traefik-import" -) diff --git a/traefik.go b/traefik.go index 5fd51a9e4..c6bd21b9b 100644 --- a/traefik.go +++ b/traefik.go @@ -3,14 +3,6 @@ package main import ( "encoding/json" "fmt" - log "github.com/Sirupsen/logrus" - "github.com/containous/flaeg" - "github.com/containous/staert" - "github.com/containous/traefik/acme" - "github.com/containous/traefik/middlewares" - "github.com/containous/traefik/provider" - "github.com/containous/traefik/types" - "github.com/docker/libkv/store" fmtlog "log" "net/http" "os" @@ -18,6 +10,16 @@ import ( "runtime" "strings" "text/template" + + log "github.com/Sirupsen/logrus" + "github.com/containous/flaeg" + "github.com/containous/staert" + "github.com/containous/traefik/acme" + "github.com/containous/traefik/middlewares" + "github.com/containous/traefik/provider" + "github.com/containous/traefik/types" + "github.com/containous/traefik/version" + "github.com/docker/libkv/store" ) var versionTemplate = `Version: {{.Version}} @@ -65,10 +67,10 @@ Complete documentation is available at https://traefik.io`, Os string Arch string }{ - Version: Version, - Codename: Codename, + Version: version.Version, + Codename: version.Codename, GoVersion: runtime.Version(), - BuildTime: BuildDate, + BuildTime: version.BuildDate, Os: runtime.GOOS, Arch: runtime.GOARCH, } @@ -184,7 +186,7 @@ func run(traefikConfiguration *TraefikConfiguration) { log.SetFormatter(&log.TextFormatter{FullTimestamp: true, DisableSorting: true}) } jsonConf, _ := json.Marshal(globalConfiguration) - log.Infof("Traefik version %s built on %s", Version, BuildDate) + log.Infof("Traefik version %s built on %s", version.Version, version.BuildDate) if len(traefikConfiguration.ConfigFile) != 0 { log.Infof("Using TOML configuration file %s", traefikConfiguration.ConfigFile) } diff --git a/version.go b/version/version.go similarity index 94% rename from version.go rename to version/version.go index 73892b697..ba72b1a42 100644 --- a/version.go +++ b/version/version.go @@ -1,4 +1,4 @@ -package main +package version var ( // Version holds the current version of traefik.