traefik/configuration.go

103 lines
2.4 KiB
Go
Raw Normal View History

2015-09-07 08:38:58 +00:00
package main
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
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
Etcd *EtcdProvider
Zookeeper *ZookepperProvider
Boltdb *BoltDbProvider
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-09-10 13:13:35 +00:00
return globalConfiguration
}
2015-09-07 08:38:58 +00:00
// Backend configuration
2015-09-07 08:38:58 +00:00
type Backend struct {
Servers map[string]Server `json:"servers,omitempty"`
CircuitBreaker *CircuitBreaker `json:"circuitBreaker,omitempty"`
LoadBalancer *LoadBalancer `json:"loadBalancer,omitempty"`
}
// LoadBalancer configuration
type LoadBalancer struct {
Method string `json:"method,omitempty"`
}
// CircuitBreaker configuration
type CircuitBreaker struct {
Expression string `json:"expression,omitempty"`
2015-09-07 08:38:58 +00:00
}
// Server configuration
2015-09-07 08:38:58 +00:00
type Server struct {
URL string `json:"url,omitempty"`
Weight int `json:"weight,omitempty"`
2015-09-07 08:38:58 +00:00
}
// Route configuration
type Route struct {
Rule string `json:"rule,omitempty"`
Value string `json:"value,omitempty"`
2015-09-07 08:38:58 +00:00
}
// Frontend configuration
type Frontend struct {
Backend string `json:"backend,omitempty"`
Routes map[string]Route `json:"routes,omitempty"`
2015-09-07 08:38:58 +00:00
}
// Configuration of a provider
2015-09-07 22:15:14 +00:00
type Configuration struct {
Backends map[string]*Backend `json:"backends,omitempty"`
Frontends map[string]*Frontend `json:"frontends,omitempty"`
}
// 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
}
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")