Move version.go in its own package…

… 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 <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2016-07-21 16:33:49 +02:00
parent 4c54a003fa
commit 87a4d73556
No known key found for this signature in database
GPG key ID: 083CC6FD6EB699A3
6 changed files with 18 additions and 31 deletions

View file

@ -6,7 +6,4 @@ Copyright
//go:generate mkdir -p static //go:generate mkdir -p static
//go:generate go-bindata -pkg autogen -o autogen/gen.go ./static/... ./templates/... //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 package main

View file

@ -15,6 +15,7 @@ import (
"github.com/cenkalti/backoff" "github.com/cenkalti/backoff"
"github.com/containous/traefik/safe" "github.com/containous/traefik/safe"
"github.com/containous/traefik/types" "github.com/containous/traefik/types"
"github.com/containous/traefik/version"
"github.com/docker/engine-api/client" "github.com/docker/engine-api/client"
dockertypes "github.com/docker/engine-api/types" dockertypes "github.com/docker/engine-api/types"
eventtypes "github.com/docker/engine-api/types/events" eventtypes "github.com/docker/engine-api/types/events"
@ -38,8 +39,7 @@ type Docker struct {
func (provider *Docker) createClient() (client.APIClient, error) { func (provider *Docker) createClient() (client.APIClient, error) {
var httpClient *http.Client var httpClient *http.Client
httpHeaders := map[string]string{ httpHeaders := map[string]string{
// FIXME(vdemeester) use version here O:) "User-Agent": "Traefik " + version.Version,
"User-Agent": "Traefik",
} }
if provider.TLS != nil { if provider.TLS != nil {
config, err := provider.TLS.CreateTLSConfig() config, err := provider.TLS.CreateTLSConfig()

View file

@ -26,4 +26,4 @@ if [ -z "$DATE" ]; then
fi fi
# Build binaries # 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 .

View file

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

View file

@ -3,14 +3,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "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" fmtlog "log"
"net/http" "net/http"
"os" "os"
@ -18,6 +10,16 @@ import (
"runtime" "runtime"
"strings" "strings"
"text/template" "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}} var versionTemplate = `Version: {{.Version}}
@ -65,10 +67,10 @@ Complete documentation is available at https://traefik.io`,
Os string Os string
Arch string Arch string
}{ }{
Version: Version, Version: version.Version,
Codename: Codename, Codename: version.Codename,
GoVersion: runtime.Version(), GoVersion: runtime.Version(),
BuildTime: BuildDate, BuildTime: version.BuildDate,
Os: runtime.GOOS, Os: runtime.GOOS,
Arch: runtime.GOARCH, Arch: runtime.GOARCH,
} }
@ -184,7 +186,7 @@ func run(traefikConfiguration *TraefikConfiguration) {
log.SetFormatter(&log.TextFormatter{FullTimestamp: true, DisableSorting: true}) log.SetFormatter(&log.TextFormatter{FullTimestamp: true, DisableSorting: true})
} }
jsonConf, _ := json.Marshal(globalConfiguration) 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 { if len(traefikConfiguration.ConfigFile) != 0 {
log.Infof("Using TOML configuration file %s", traefikConfiguration.ConfigFile) log.Infof("Using TOML configuration file %s", traefikConfiguration.ConfigFile)
} }

View file

@ -1,4 +1,4 @@
package main package version
var ( var (
// Version holds the current version of traefik. // Version holds the current version of traefik.