Fix panic on help, Better version

Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
Emile Vauge 2016-06-02 15:17:04 +02:00
parent 423268f485
commit 3f08bb4cdf
No known key found for this signature in database
GPG key ID: D808B4C167352E59
8 changed files with 133 additions and 68 deletions

View file

@ -26,7 +26,7 @@ type GlobalConfiguration struct {
TraefikLogsFile string `description:"Traefik logs file"` TraefikLogsFile string `description:"Traefik logs file"`
LogLevel string `short:"l" description:"Log level"` LogLevel string `short:"l" description:"Log level"`
EntryPoints EntryPoints `description:"Entrypoints definition using format: --entryPoints='Name:http Address::8000 Redirect.EntryPoint:https' --entryPoints='Name:https Address::4442 TLS:tests/traefik.crt,tests/traefik.key'"` EntryPoints EntryPoints `description:"Entrypoints definition using format: --entryPoints='Name:http Address::8000 Redirect.EntryPoint:https' --entryPoints='Name:https Address::4442 TLS:tests/traefik.crt,tests/traefik.key'"`
Constraints Constraints `description:"Filter services by constraint, matching with service tags."` Constraints types.Constraints `description:"Filter services by constraint, matching with service tags."`
ACME *acme.ACME `description:"Enable ACME (Let's Encrypt): automatic SSL"` ACME *acme.ACME `description:"Enable ACME (Let's Encrypt): automatic SSL"`
DefaultEntryPoints DefaultEntryPoints `description:"Entrypoints to be used by frontends that do not specify any entrypoint"` DefaultEntryPoints DefaultEntryPoints `description:"Entrypoints to be used by frontends that do not specify any entrypoint"`
ProvidersThrottleDuration time.Duration `description:"Backends throttle duration: minimum duration between 2 events from providers before applying a new configuration. It avoids unnecessary reloads if multiples events are sent in a short amount of time."` ProvidersThrottleDuration time.Duration `description:"Backends throttle duration: minimum duration between 2 events from providers before applying a new configuration. It avoids unnecessary reloads if multiples events are sent in a short amount of time."`
@ -143,42 +143,7 @@ func (ep *EntryPoints) SetValue(val interface{}) {
// Type is type of the struct // Type is type of the struct
func (ep *EntryPoints) Type() string { func (ep *EntryPoints) Type() string {
return fmt.Sprint("entrypoints²") return fmt.Sprint("entrypoints")
}
// Constraints holds a Constraint parser
type Constraints []types.Constraint
//Set []*Constraint
func (cs *Constraints) Set(str string) error {
exps := strings.Split(str, ",")
if len(exps) == 0 {
return errors.New("Bad Constraint format: " + str)
}
for _, exp := range exps {
constraint, err := types.NewConstraint(exp)
if err != nil {
return err
}
*cs = append(*cs, *constraint)
}
return nil
}
//Get []*Constraint
func (cs *Constraints) Get() interface{} { return []types.Constraint(*cs) }
//String returns []*Constraint in string
func (cs *Constraints) String() string { return fmt.Sprintf("%+v", *cs) }
//SetValue sets []*Constraint into the parser
func (cs *Constraints) SetValue(val interface{}) {
*cs = Constraints(val.([]types.Constraint))
}
// Type exports the Constraints type as a string
func (cs *Constraints) Type() string {
return fmt.Sprint("constraint²")
} }
// EntryPoint holds an entry point configuration of the reverse proxy (ip, port, TLS...) // EntryPoint holds an entry point configuration of the reverse proxy (ip, port, TLS...)

42
glide.lock generated
View file

@ -1,5 +1,5 @@
hash: 1d42530971835a5a1e593e8efc54f28f2714cb8d1dfcb333e3b9ba92ef1917cc hash: dc59755b72e71945a21135c5a37e4a5c11ae511ac7404d1440166ea0aed736c4
updated: 2016-05-30T16:53:17.058435869+02:00 updated: 2016-06-02T15:11:52.77657652+02:00
imports: imports:
- name: github.com/boltdb/bolt - name: github.com/boltdb/bolt
version: dfb21201d9270c1082d5fb0f07f500311ff72f18 version: dfb21201d9270c1082d5fb0f07f500311ff72f18
@ -10,15 +10,15 @@ imports:
subpackages: subpackages:
- fun - fun
- name: github.com/cenkalti/backoff - name: github.com/cenkalti/backoff
version: c29158af31815ccc31ca29c86c121bc39e00d3d8 version: a6030178a585d5972d4d33ce61f4a1fa40eaaed0
- name: github.com/codahale/hdrhistogram - name: github.com/codahale/hdrhistogram
version: 9208b142303c12d8899bae836fd524ac9338b4fd version: 9208b142303c12d8899bae836fd524ac9338b4fd
- name: github.com/codegangsta/cli - name: github.com/codegangsta/cli
version: bf4a526f48af7badd25d2cb02d587e1b01be3b50 version: bf4a526f48af7badd25d2cb02d587e1b01be3b50
- name: github.com/codegangsta/negroni - name: github.com/codegangsta/negroni
version: ffbc66b612ee3eac2eba29aedce4c3a65e4dd0a1 version: fb7b7c045dfb05dc81a5c3688c568550b5bd6e36
- name: github.com/containous/flaeg - name: github.com/containous/flaeg
version: a208db24c0e580be76efed167736fe3204c7c954 version: b98687da5c323650f4513fda6b6203fcbdec9313
- name: github.com/containous/oxy - name: github.com/containous/oxy
version: 183212964e13e7b8afe01a08b193d04300554a68 version: 183212964e13e7b8afe01a08b193d04300554a68
subpackages: subpackages:
@ -29,7 +29,7 @@ imports:
- stream - stream
- utils - utils
- name: github.com/containous/staert - name: github.com/containous/staert
version: 9f815ef829b66de3519fea6c0b8d4708eb9472d4 version: e2aa88e235a02dd52aa1d5d9de75f9d9139d1602
- name: github.com/coreos/etcd - name: github.com/coreos/etcd
version: c400d05d0aa73e21e431c16145e558d624098018 version: c400d05d0aa73e21e431c16145e558d624098018
subpackages: subpackages:
@ -43,7 +43,7 @@ imports:
subpackages: subpackages:
- spew - spew
- name: github.com/docker/distribution - name: github.com/docker/distribution
version: 5bbf65499960b184fe8e0f045397375e1a6722b8 version: bb330cd684eb4afab9cc4f2453d7c8918099d7ee
subpackages: subpackages:
- reference - reference
- digest - digest
@ -75,7 +75,7 @@ imports:
- tlsconfig - tlsconfig
- nat - nat
- name: github.com/docker/go-units - name: github.com/docker/go-units
version: 5d2041e26a699eaca682e2ea41c8f891e1060444 version: 09dda9d4b0d748c57c14048906d3d094a58ec0c9
- name: github.com/docker/libcompose - name: github.com/docker/libcompose
version: 8ee7bcc364f7b8194581a3c6bd9fa019467c7873 version: 8ee7bcc364f7b8194581a3c6bd9fa019467c7873
- name: github.com/docker/libkv - name: github.com/docker/libkv
@ -87,7 +87,7 @@ imports:
- store/etcd - store/etcd
- store/zookeeper - store/zookeeper
- name: github.com/donovanhide/eventsource - name: github.com/donovanhide/eventsource
version: c3f57f280ec708df24886d9e62f2fd178d69d8e8 version: fd1de70867126402be23c306e1ce32828455d85b
- name: github.com/elazarl/go-bindata-assetfs - name: github.com/elazarl/go-bindata-assetfs
version: 57eb5e1fc594ad4b0b1dbea7b286d299e0cb43c2 version: 57eb5e1fc594ad4b0b1dbea7b286d299e0cb43c2
- name: github.com/gambol99/go-marathon - name: github.com/gambol99/go-marathon
@ -99,11 +99,11 @@ imports:
subpackages: subpackages:
- query - query
- name: github.com/gorilla/context - name: github.com/gorilla/context
version: a8d44e7d8e4d532b6a27a02dd82abb31cc1b01bd version: aed02d124ae4a0e94fea4541c8effd05bf0c8296
- name: github.com/gorilla/mux - name: github.com/gorilla/mux
version: 9c19ed558d5df4da88e2ade9c8940d742aef0e7e version: bd09be08ed4377796d312df0a45314e11b8f5dc1
- name: github.com/hashicorp/consul - name: github.com/hashicorp/consul
version: f6fef66e1bf17be4f3c9855fbec6de802ca6bd7d version: ebf7ea1d759184c02a5bb5263a7c52d29838ffc3
subpackages: subpackages:
- api - api
- name: github.com/hashicorp/go-cleanhttp - name: github.com/hashicorp/go-cleanhttp
@ -136,27 +136,29 @@ imports:
- name: github.com/ogier/pflag - name: github.com/ogier/pflag
version: 45c278ab3607870051a2ea9040bb85fcb8557481 version: 45c278ab3607870051a2ea9040bb85fcb8557481
- name: github.com/opencontainers/runc - name: github.com/opencontainers/runc
version: d2d09b9bcd0573c58d7cd94e57bd7555af0c2072 version: 6c485e6902bb9dd77b8234042b8f00e20ef87a18
subpackages: subpackages:
- libcontainer/user - libcontainer/user
- name: github.com/parnurzeal/gorequest - name: github.com/parnurzeal/gorequest
version: 2169dfca686cfcbefc983a98a25e9c22a2815be4 version: f17fef20c518e688f4edb3eb2af148462ecab3ef
- name: github.com/pmezard/go-difflib - name: github.com/pmezard/go-difflib
version: d8ed2627bdf02c080bf22230dbb337003b7aba2d version: d8ed2627bdf02c080bf22230dbb337003b7aba2d
subpackages: subpackages:
- difflib - difflib
- name: github.com/ryanuber/go-glob
version: 572520ed46dbddaed19ea3d9541bdd0494163693
- name: github.com/samuel/go-zookeeper - name: github.com/samuel/go-zookeeper
version: 6eb1b09c6ce23f305f4c81bf748b22fbc6f3f9e9 version: 4b20de542e40ed2b89d65ae195fc20a330919b92
subpackages: subpackages:
- zk - zk
- name: github.com/Sirupsen/logrus - name: github.com/Sirupsen/logrus
version: 6d9ae300aaf85d6acd2e5424081c7fcddb21dab8 version: f3cfb454f4c209e6668c95216c4744b8fddb2356
- name: github.com/streamrail/concurrent-map - name: github.com/streamrail/concurrent-map
version: 65a174a3a4188c0b7099acbc6cfa0c53628d3287 version: 65a174a3a4188c0b7099acbc6cfa0c53628d3287
- name: github.com/stretchr/objx - name: github.com/stretchr/objx
version: cbeaeb16a013161a98496fad62933b1d21786672 version: cbeaeb16a013161a98496fad62933b1d21786672
- name: github.com/stretchr/testify - name: github.com/stretchr/testify
version: 6cb3b85ef5a0efef77caef88363ec4d4b5c0976d version: 8d64eb7173c7753d6419fd4a9caf057398611364
subpackages: subpackages:
- mock - mock
- assert - assert
@ -165,7 +167,7 @@ imports:
- name: github.com/unrolled/render - name: github.com/unrolled/render
version: 198ad4d8b8a4612176b804ca10555b222a086b40 version: 198ad4d8b8a4612176b804ca10555b222a086b40
- name: github.com/vdemeester/docker-events - name: github.com/vdemeester/docker-events
version: b308d2e8d639d928c882913bcb4f85b3a84c7a07 version: 20e6d2db238723e68197a9e3c6c34c99a9893a9c
- name: github.com/vdemeester/shakers - name: github.com/vdemeester/shakers
version: 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3 version: 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3
- name: github.com/vulcand/oxy - name: github.com/vulcand/oxy
@ -184,7 +186,7 @@ imports:
- plugin - plugin
- router - router
- name: github.com/xenolf/lego - name: github.com/xenolf/lego
version: b119bc45fbd1cc71348003541aac9d3a7da63654 version: 30a7a8e8821de3532192d1240a45e53c6204f603
subpackages: subpackages:
- acme - acme
- name: golang.org/x/crypto - name: golang.org/x/crypto
@ -213,6 +215,4 @@ imports:
subpackages: subpackages:
- cipher - cipher
- json - json
- name: github.com/ryanuber/go-glob
version: 572520ed46dbddaed19ea3d9541bdd0494163693
devImports: [] devImports: []

View file

@ -8,7 +8,7 @@ import:
- package: github.com/cenkalti/backoff - package: github.com/cenkalti/backoff
- package: github.com/codegangsta/negroni - package: github.com/codegangsta/negroni
- package: github.com/containous/flaeg - package: github.com/containous/flaeg
version: a208db24c0e580be76efed167736fe3204c7c954 version: b98687da5c323650f4513fda6b6203fcbdec9313
- package: github.com/containous/oxy - package: github.com/containous/oxy
subpackages: subpackages:
- cbreaker - cbreaker
@ -18,7 +18,7 @@ import:
- stream - stream
- utils - utils
- package: github.com/containous/staert - package: github.com/containous/staert
version: 9f815ef829b66de3519fea6c0b8d4708eb9472d4 version: e2aa88e235a02dd52aa1d5d9de75f9d9139d1602
- package: github.com/docker/engine-api - package: github.com/docker/engine-api
version: 3d3d0b6c9d2651aac27f416a6da0224c1875b3eb version: 3d3d0b6c9d2651aac27f416a6da0224c1875b3eb
subpackages: subpackages:

View file

@ -57,3 +57,34 @@ func (s *SimpleSuite) TestWithWebConfig(c *check.C) {
c.Assert(err, checker.IsNil) c.Assert(err, checker.IsNil)
c.Assert(resp.StatusCode, checker.Equals, 200) c.Assert(resp.StatusCode, checker.Equals, 200)
} }
func (s *SimpleSuite) TestDefaultEntryPoints(c *check.C) {
cmd := exec.Command(traefikBinary, "--debug")
var b bytes.Buffer
cmd.Stdout = &b
cmd.Stderr = &b
cmd.Start()
time.Sleep(500 * time.Millisecond)
defer cmd.Process.Kill()
output := b.Bytes()
c.Assert(string(output), checker.Contains, "\\\"DefaultEntryPoints\\\":[\\\"http\\\"]")
}
func (s *SimpleSuite) TestPrintHelp(c *check.C) {
cmd := exec.Command(traefikBinary, "--help")
var b bytes.Buffer
cmd.Stdout = &b
cmd.Stderr = &b
cmd.Start()
time.Sleep(500 * time.Millisecond)
defer cmd.Process.Kill()
output := b.Bytes()
c.Assert(string(output), checker.Not(checker.Contains), "panic:")
c.Assert(string(output), checker.Contains, "Usage:")
}

View file

@ -24,7 +24,7 @@ type Provider interface {
type BaseProvider struct { type BaseProvider struct {
Watch bool `description:"Watch provider"` Watch bool `description:"Watch provider"`
Filename string `description:"Override default configuration template. For advanced users :)"` Filename string `description:"Override default configuration template. For advanced users :)"`
Constraints []types.Constraint `description:"Filter services by constraint, matching with Traefik tags."` Constraints types.Constraints `description:"Filter services by constraint, matching with Traefik tags."`
} }
// MatchConstraints must match with EVERY single contraint // MatchConstraints must match with EVERY single contraint

View file

@ -2,6 +2,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/containous/flaeg" "github.com/containous/flaeg"
"github.com/containous/staert" "github.com/containous/staert"
@ -15,8 +16,14 @@ import (
"reflect" "reflect"
"runtime" "runtime"
"strings" "strings"
"text/template"
) )
var versionTemplate = `Version: {{.Version}}
Go version: {{.GoVersion}}
Built: {{.BuildTime}}
OS/Arch: {{.Os}}/{{.Arch}}`
func main() { func main() {
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())
@ -43,8 +50,31 @@ Complete documentation is available at https://traefik.io`,
Config: struct{}{}, Config: struct{}{},
DefaultPointersConfig: struct{}{}, DefaultPointersConfig: struct{}{},
Run: func() error { Run: func() error {
fmtlog.Println(Version + " built on the " + BuildDate) tmpl, err := template.New("").Parse(versionTemplate)
if err != nil {
return err
}
v := struct {
Version string
GoVersion string
BuildTime string
Os string
Arch string
}{
Version: Version,
GoVersion: runtime.Version(),
BuildTime: BuildDate,
Os: runtime.GOOS,
Arch: runtime.GOARCH,
}
if err := tmpl.Execute(os.Stdout, v); err != nil {
return err
}
fmt.Printf("\n")
return nil return nil
}, },
} }
@ -53,8 +83,7 @@ Complete documentation is available at https://traefik.io`,
//add custom parsers //add custom parsers
f.AddParser(reflect.TypeOf(EntryPoints{}), &EntryPoints{}) f.AddParser(reflect.TypeOf(EntryPoints{}), &EntryPoints{})
f.AddParser(reflect.TypeOf(DefaultEntryPoints{}), &DefaultEntryPoints{}) f.AddParser(reflect.TypeOf(DefaultEntryPoints{}), &DefaultEntryPoints{})
f.AddParser(reflect.TypeOf([]types.Constraint{}), &Constraints{}) f.AddParser(reflect.TypeOf(types.Constraints{}), &types.Constraints{})
f.AddParser(reflect.TypeOf(Constraints{}), &Constraints{})
f.AddParser(reflect.TypeOf(provider.Namespaces{}), &provider.Namespaces{}) f.AddParser(reflect.TypeOf(provider.Namespaces{}), &provider.Namespaces{})
f.AddParser(reflect.TypeOf([]acme.Domain{}), &acme.Domains{}) f.AddParser(reflect.TypeOf([]acme.Domain{}), &acme.Domains{})
@ -111,6 +140,10 @@ func run(traefikConfiguration *TraefikConfiguration) {
globalConfiguration.DefaultEntryPoints = []string{"http"} globalConfiguration.DefaultEntryPoints = []string{"http"}
} }
if globalConfiguration.Debug {
globalConfiguration.LogLevel = "DEBUG"
}
// logging // logging
level, err := log.ParseLevel(strings.ToLower(globalConfiguration.LogLevel)) level, err := log.ParseLevel(strings.ToLower(globalConfiguration.LogLevel))
if err != nil { if err != nil {

View file

@ -2,6 +2,7 @@ package types
import ( import (
"errors" "errors"
"fmt"
"github.com/ryanuber/go-glob" "github.com/ryanuber/go-glob"
"strings" "strings"
) )
@ -150,3 +151,38 @@ func (c *Constraint) MatchConstraintWithAtLeastOneTag(tags []string) bool {
} }
return false return false
} }
//Set []*Constraint
func (cs *Constraints) Set(str string) error {
exps := strings.Split(str, ",")
if len(exps) == 0 {
return errors.New("Bad Constraint format: " + str)
}
for _, exp := range exps {
constraint, err := NewConstraint(exp)
if err != nil {
return err
}
*cs = append(*cs, *constraint)
}
return nil
}
// Constraints holds a Constraint parser
type Constraints []Constraint
//Get []*Constraint
func (cs *Constraints) Get() interface{} { return []Constraint(*cs) }
//String returns []*Constraint in string
func (cs *Constraints) String() string { return fmt.Sprintf("%+v", *cs) }
//SetValue sets []*Constraint into the parser
func (cs *Constraints) SetValue(val interface{}) {
*cs = Constraints(val.(Constraints))
}
// Type exports the Constraints type as a string
func (cs *Constraints) Type() string {
return fmt.Sprint("constraint")
}

View file

@ -2,7 +2,7 @@ package main
var ( var (
// Version holds the current version of traefik. // Version holds the current version of traefik.
Version = "" Version = "dev"
// BuildDate holds the build date of traefik. // BuildDate holds the build date of traefik.
BuildDate = "" BuildDate = "I don't remember exactly"
) )