Use of Viper and cobra
This commit is contained in:
parent
a0b15a0efd
commit
35070f7c1c
32 changed files with 414 additions and 143 deletions
|
@ -8,13 +8,13 @@ import (
|
|||
|
||||
// BoltDb holds configurations of the BoltDb provider.
|
||||
type BoltDb struct {
|
||||
Kv
|
||||
Kv `mapstructure:",squash"`
|
||||
}
|
||||
|
||||
// Provide allows the provider to provide configurations to traefik
|
||||
// using the given configuration channel.
|
||||
func (provider *BoltDb) Provide(configurationChan chan<- types.ConfigMessage) error {
|
||||
provider.StoreType = store.BOLTDB
|
||||
provider.storeType = store.BOLTDB
|
||||
boltdb.Register()
|
||||
return provider.provide(configurationChan)
|
||||
}
|
||||
|
|
|
@ -8,13 +8,13 @@ import (
|
|||
|
||||
// Consul holds configurations of the Consul provider.
|
||||
type Consul struct {
|
||||
Kv
|
||||
Kv `mapstructure:",squash"`
|
||||
}
|
||||
|
||||
// Provide allows the provider to provide configurations to traefik
|
||||
// using the given configuration channel.
|
||||
func (provider *Consul) Provide(configurationChan chan<- types.ConfigMessage) error {
|
||||
provider.StoreType = store.CONSUL
|
||||
provider.storeType = store.CONSUL
|
||||
consul.Register()
|
||||
return provider.provide(configurationChan)
|
||||
}
|
||||
|
|
|
@ -17,10 +17,10 @@ import (
|
|||
|
||||
// Docker holds configurations of the Docker provider.
|
||||
type Docker struct {
|
||||
baseProvider
|
||||
Endpoint string
|
||||
Domain string
|
||||
TLS *DockerTLS
|
||||
BaseProvider `mapstructure:",squash"`
|
||||
Endpoint string
|
||||
Domain string
|
||||
TLS *DockerTLS
|
||||
}
|
||||
|
||||
// DockerTLS holds TLS specific configurations
|
||||
|
|
|
@ -8,13 +8,13 @@ import (
|
|||
|
||||
// Etcd holds configurations of the Etcd provider.
|
||||
type Etcd struct {
|
||||
Kv
|
||||
Kv `mapstructure:",squash"`
|
||||
}
|
||||
|
||||
// Provide allows the provider to provide configurations to traefik
|
||||
// using the given configuration channel.
|
||||
func (provider *Etcd) Provide(configurationChan chan<- types.ConfigMessage) error {
|
||||
provider.StoreType = store.ETCD
|
||||
provider.storeType = store.ETCD
|
||||
etcd.Register()
|
||||
return provider.provide(configurationChan)
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
// File holds configurations of the File provider.
|
||||
type File struct {
|
||||
baseProvider
|
||||
BaseProvider `mapstructure:",squash"`
|
||||
}
|
||||
|
||||
// Provide allows the provider to provide configurations to traefik
|
||||
|
|
|
@ -15,16 +15,16 @@ import (
|
|||
|
||||
// Kv holds common configurations of key-value providers.
|
||||
type Kv struct {
|
||||
baseProvider
|
||||
Endpoint string
|
||||
Prefix string
|
||||
StoreType store.Backend
|
||||
kvclient store.Store
|
||||
BaseProvider `mapstructure:",squash"`
|
||||
Endpoint string
|
||||
Prefix string
|
||||
storeType store.Backend
|
||||
kvclient store.Store
|
||||
}
|
||||
|
||||
func (provider *Kv) provide(configurationChan chan<- types.ConfigMessage) error {
|
||||
kv, err := libkv.NewStore(
|
||||
provider.StoreType,
|
||||
provider.storeType,
|
||||
[]string{provider.Endpoint},
|
||||
&store.Config{
|
||||
ConnectionTimeout: 30 * time.Second,
|
||||
|
@ -50,7 +50,7 @@ func (provider *Kv) provide(configurationChan chan<- types.ConfigMessage) error
|
|||
configuration := provider.loadConfig()
|
||||
if configuration != nil {
|
||||
configurationChan <- types.ConfigMessage{
|
||||
ProviderName: string(provider.StoreType),
|
||||
ProviderName: string(provider.storeType),
|
||||
Configuration: configuration,
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ func (provider *Kv) provide(configurationChan chan<- types.ConfigMessage) error
|
|||
}
|
||||
configuration := provider.loadConfig()
|
||||
configurationChan <- types.ConfigMessage{
|
||||
ProviderName: string(provider.StoreType),
|
||||
ProviderName: string(provider.storeType),
|
||||
Configuration: configuration,
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -14,7 +14,7 @@ import (
|
|||
|
||||
// Marathon holds configuration of the Marathon provider.
|
||||
type Marathon struct {
|
||||
baseProvider
|
||||
BaseProvider `mapstructure:",squash"`
|
||||
Endpoint string
|
||||
Domain string
|
||||
NetworkInterface string
|
||||
|
|
|
@ -18,12 +18,13 @@ type Provider interface {
|
|||
Provide(configurationChan chan<- types.ConfigMessage) error
|
||||
}
|
||||
|
||||
type baseProvider struct {
|
||||
// BaseProvider should be inherited by providers
|
||||
type BaseProvider struct {
|
||||
Watch bool
|
||||
Filename string
|
||||
}
|
||||
|
||||
func (p *baseProvider) getConfiguration(defaultTemplateFile string, funcMap template.FuncMap, templateObjects interface{}) (*types.Configuration, error) {
|
||||
func (p *BaseProvider) getConfiguration(defaultTemplateFile string, funcMap template.FuncMap, templateObjects interface{}) (*types.Configuration, error) {
|
||||
var (
|
||||
buf []byte
|
||||
err error
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
)
|
||||
|
||||
type myProvider struct {
|
||||
baseProvider
|
||||
BaseProvider
|
||||
}
|
||||
|
||||
func (p *myProvider) Foo() string {
|
||||
|
@ -49,7 +49,7 @@ func TestConfigurationErrors(t *testing.T) {
|
|||
}{
|
||||
{
|
||||
provider: &myProvider{
|
||||
baseProvider{
|
||||
BaseProvider{
|
||||
Filename: "/non/existent/template.tmpl",
|
||||
},
|
||||
},
|
||||
|
@ -62,7 +62,7 @@ func TestConfigurationErrors(t *testing.T) {
|
|||
},
|
||||
{
|
||||
provider: &myProvider{
|
||||
baseProvider{
|
||||
BaseProvider{
|
||||
Filename: templateErrorFile.Name(),
|
||||
},
|
||||
},
|
||||
|
@ -70,7 +70,7 @@ func TestConfigurationErrors(t *testing.T) {
|
|||
},
|
||||
{
|
||||
provider: &myProvider{
|
||||
baseProvider{
|
||||
BaseProvider{
|
||||
Filename: templateInvalidTOMLFile.Name(),
|
||||
},
|
||||
},
|
||||
|
@ -125,7 +125,7 @@ func TestGetConfiguration(t *testing.T) {
|
|||
}
|
||||
|
||||
provider := &myProvider{
|
||||
baseProvider{
|
||||
BaseProvider{
|
||||
Filename: templateFile.Name(),
|
||||
},
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ type Zookepper struct {
|
|||
// Provide allows the provider to provide configurations to traefik
|
||||
// using the given configuration channel.
|
||||
func (provider *Zookepper) Provide(configurationChan chan<- types.ConfigMessage) error {
|
||||
provider.StoreType = store.ZK
|
||||
provider.storeType = store.ZK
|
||||
zookeeper.Register()
|
||||
return provider.provide(configurationChan)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue