2015-09-07 08:38:58 +00:00
|
|
|
package main
|
|
|
|
|
2015-09-25 09:44:19 +00:00
|
|
|
import (
|
2015-11-06 17:11:57 +00:00
|
|
|
fmtlog "log"
|
2015-10-08 15:56:45 +00:00
|
|
|
"time"
|
2015-11-01 15:35:01 +00:00
|
|
|
|
2015-11-06 17:11:57 +00:00
|
|
|
"github.com/BurntSushi/toml"
|
2015-11-01 15:35:01 +00:00
|
|
|
"github.com/emilevauge/traefik/provider"
|
|
|
|
"github.com/emilevauge/traefik/types"
|
2015-09-25 09:44:19 +00:00
|
|
|
)
|
|
|
|
|
2015-11-06 17:11:57 +00:00
|
|
|
// GlobalConfiguration holds global configuration (with providers, etc.).
|
|
|
|
// It's populated from the traefik configuration file passed as an argument to the binary.
|
2015-09-10 13:13:35 +00:00
|
|
|
type GlobalConfiguration struct {
|
2015-10-17 12:14:20 +00:00
|
|
|
Port string
|
|
|
|
GraceTimeOut int64
|
|
|
|
AccessLogsFile string
|
|
|
|
TraefikLogsFile string
|
2015-11-21 01:59:49 +00:00
|
|
|
Certificates []Certificate
|
2015-10-17 12:14:20 +00:00
|
|
|
LogLevel string
|
|
|
|
ProvidersThrottleDuration time.Duration
|
2015-11-02 18:48:34 +00:00
|
|
|
Docker *provider.Docker
|
|
|
|
File *provider.File
|
2015-10-17 12:14:20 +00:00
|
|
|
Web *WebProvider
|
2015-11-02 18:48:34 +00:00
|
|
|
Marathon *provider.Marathon
|
|
|
|
Consul *provider.Consul
|
|
|
|
Etcd *provider.Etcd
|
|
|
|
Zookeeper *provider.Zookepper
|
|
|
|
Boltdb *provider.BoltDb
|
2015-09-10 13:13:35 +00:00
|
|
|
}
|
|
|
|
|
2015-11-21 01:59:49 +00:00
|
|
|
// Certificate holds a SSL cert/key pair
|
|
|
|
type Certificate struct {
|
|
|
|
CertFile string
|
|
|
|
KeyFile string
|
|
|
|
}
|
|
|
|
|
2015-11-06 17:11:57 +00:00
|
|
|
// NewGlobalConfiguration returns a GlobalConfiguration with default values.
|
2015-09-10 13:13:35 +00:00
|
|
|
func NewGlobalConfiguration() *GlobalConfiguration {
|
|
|
|
globalConfiguration := new(GlobalConfiguration)
|
|
|
|
// default values
|
2015-09-14 12:38:21 +00:00
|
|
|
globalConfiguration.Port = ":80"
|
2015-09-10 13:13:35 +00:00
|
|
|
globalConfiguration.GraceTimeOut = 10
|
2015-09-11 14:40:54 +00:00
|
|
|
globalConfiguration.LogLevel = "ERROR"
|
2015-10-17 12:14:20 +00:00
|
|
|
globalConfiguration.ProvidersThrottleDuration = time.Duration(2 * time.Second)
|
2015-09-10 13:13:35 +00:00
|
|
|
|
|
|
|
return globalConfiguration
|
|
|
|
}
|
2015-09-07 08:38:58 +00:00
|
|
|
|
2015-11-06 17:11:57 +00:00
|
|
|
// LoadFileConfig returns a GlobalConfiguration from reading the specified file (a toml file).
|
|
|
|
func LoadFileConfig(file string) *GlobalConfiguration {
|
|
|
|
configuration := NewGlobalConfiguration()
|
|
|
|
if _, err := toml.DecodeFile(file, configuration); err != nil {
|
|
|
|
fmtlog.Fatalf("Error reading file: %s", err)
|
|
|
|
}
|
|
|
|
return configuration
|
|
|
|
}
|
|
|
|
|
2015-11-01 15:35:01 +00:00
|
|
|
type configs map[string]*types.Configuration
|