2015-09-07 08:38:58 +00:00
|
|
|
package main
|
|
|
|
|
2015-09-25 09:44:19 +00:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2015-09-10 13:13:35 +00:00
|
|
|
type GlobalConfiguration struct {
|
2015-09-11 14:37:13 +00:00
|
|
|
Port string
|
|
|
|
GraceTimeOut int64
|
|
|
|
AccessLogsFile string
|
|
|
|
TraefikLogsFile string
|
|
|
|
TraefikLogsStdout bool
|
2015-09-11 14:48:52 +00:00
|
|
|
CertFile, KeyFile string
|
2015-09-11 14:37:13 +00:00
|
|
|
LogLevel string
|
|
|
|
Docker *DockerProvider
|
|
|
|
File *FileProvider
|
|
|
|
Web *WebProvider
|
|
|
|
Marathon *MarathonProvider
|
2015-09-21 16:05:56 +00:00
|
|
|
Consul *ConsulProvider
|
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.TraefikLogsStdout = true
|
2015-09-10 13:13:35 +00:00
|
|
|
|
|
|
|
return globalConfiguration
|
|
|
|
}
|
2015-09-07 08:38:58 +00:00
|
|
|
|
|
|
|
type Backend struct {
|
2015-09-25 09:44:19 +00:00
|
|
|
Servers map[string]Server
|
|
|
|
CircuitBreaker *CircuitBreaker
|
|
|
|
LoadBalancer *LoadBalancer
|
|
|
|
}
|
|
|
|
|
|
|
|
type LoadBalancer struct {
|
|
|
|
Method string
|
|
|
|
}
|
|
|
|
|
|
|
|
type CircuitBreaker struct {
|
|
|
|
Expression string
|
2015-09-07 08:38:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Server struct {
|
2015-09-24 20:17:40 +00:00
|
|
|
URL string
|
2015-09-10 14:14:08 +00:00
|
|
|
Weight int
|
2015-09-07 08:38:58 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 14:09:21 +00:00
|
|
|
type Route struct {
|
2015-09-15 20:32:09 +00:00
|
|
|
Rule string
|
|
|
|
Value string
|
2015-09-07 08:38:58 +00:00
|
|
|
}
|
|
|
|
|
2015-09-15 14:09:21 +00:00
|
|
|
type Frontend struct {
|
2015-09-09 15:41:33 +00:00
|
|
|
Backend string
|
2015-09-15 20:32:09 +00:00
|
|
|
Routes map[string]Route
|
2015-09-07 08:38:58 +00:00
|
|
|
}
|
|
|
|
|
2015-09-07 22:15:14 +00:00
|
|
|
type Configuration struct {
|
2015-09-25 09:44:19 +00:00
|
|
|
Backends map[string]*Backend
|
|
|
|
Frontends map[string]*Frontend
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load Balancer Method
|
|
|
|
type LoadBalancerMethod uint8
|
|
|
|
|
|
|
|
const (
|
|
|
|
// wrr (default) = Weighted Round Robin
|
|
|
|
wrr LoadBalancerMethod = iota
|
|
|
|
// drr = Dynamic Round Robin
|
|
|
|
drr
|
|
|
|
)
|
|
|
|
|
|
|
|
var loadBalancerMethodNames = []string{
|
|
|
|
"wrr",
|
|
|
|
"drr",
|
2015-09-12 13:10:03 +00:00
|
|
|
}
|
2015-09-25 09:44:19 +00:00
|
|
|
|
|
|
|
func NewLoadBalancerMethod(loadBalancer *LoadBalancer) (LoadBalancerMethod, error) {
|
|
|
|
if loadBalancer != nil {
|
|
|
|
for i, name := range loadBalancerMethodNames {
|
|
|
|
if strings.EqualFold(name, loadBalancer.Method) {
|
|
|
|
return LoadBalancerMethod(i), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return wrr, ErrInvalidLoadBalancerMethod
|
|
|
|
}
|
|
|
|
|
|
|
|
var ErrInvalidLoadBalancerMethod = errors.New("Invalid method, using default")
|