traefik/configuration.go

60 lines
1.8 KiB
Go
Raw Normal View History

2015-09-07 08:38:58 +00:00
package main
import (
fmtlog "log"
"time"
"github.com/BurntSushi/toml"
"github.com/emilevauge/traefik/provider"
"github.com/emilevauge/traefik/types"
)
// 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 {
Port string
GraceTimeOut int64
AccessLogsFile string
TraefikLogsFile string
2015-11-21 01:59:49 +00:00
Certificates []Certificate
LogLevel string
ProvidersThrottleDuration time.Duration
Docker *provider.Docker
File *provider.File
Web *WebProvider
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
}
// 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"
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
// 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
}
type configs map[string]*types.Configuration