From a4f542c02f539b1e7ce7cf95b15b48a6d3a3e2c8 Mon Sep 17 00:00:00 2001 From: emile Date: Tue, 15 Sep 2015 16:09:21 +0200 Subject: [PATCH] refactor rules -> routes, routes -> frontends --- configuration.go | 8 ++--- providerTemplates/docker.tmpl | 6 ++-- providerTemplates/marathon.tmpl | 6 ++-- templates/configuration.tmpl | 62 ++++++++++++++++----------------- traefik.go | 22 ++++++------ traefik.sample.toml | 10 +++--- traefik.toml | 10 +++--- 7 files changed, 62 insertions(+), 62 deletions(-) diff --git a/configuration.go b/configuration.go index bb0921218..4443a2508 100644 --- a/configuration.go +++ b/configuration.go @@ -34,17 +34,17 @@ type Server struct { Weight int } -type Rule struct { +type Route struct { Category string Value string } -type Route struct { +type Frontend struct { Backend string - Rules map[string]Rule + Routes map[string]Route } type Configuration struct { Backends map[string]Backend - Routes map[string]Route + Frontends map[string]Frontend } diff --git a/providerTemplates/docker.tmpl b/providerTemplates/docker.tmpl index 28ff42b98..bbc0be8fe 100644 --- a/providerTemplates/docker.tmpl +++ b/providerTemplates/docker.tmpl @@ -4,11 +4,11 @@ weight = {{getWeight .}} {{end}} -[routes]{{range $host, $containers := .Hosts}} - [routes.route-{{$host}}] +[frontends]{{range $host, $containers := .Hosts}} + [frontends.frontend-{{$host}}] {{$container := index $containers 0}} backend = "backend-{{getBackend $container}}" - [routes.route-{{$host}}.rules.rule-host-{{$host}}] + [frontends.frontend-{{$host}}.routes.route-host-{{$host}}] category = "Host" value = "{{$host}}.{{$.Domain}}" {{end}} \ No newline at end of file diff --git a/providerTemplates/marathon.tmpl b/providerTemplates/marathon.tmpl index a00c02699..bd70edeab 100644 --- a/providerTemplates/marathon.tmpl +++ b/providerTemplates/marathon.tmpl @@ -10,10 +10,10 @@ {{end}} {{end}} -[routes]{{range .Applications}} - [routes.route{{.ID | replace "/" "-"}}] +[frontends]{{range .Applications}} + [frontends.frontend{{.ID | replace "/" "-"}}] backend = "backend{{.ID | replace "/" "-"}}" - [routes.route-{{getHost . | replace "/" "-"}}.rules.rule-host-{{getHost . | replace "/" "-"}}] + [frontends.frontend-{{getHost . | replace "/" "-"}}.routes.route-host-{{getHost . | replace "/" "-"}}] category = "Host" value = "{{getHost . | replace "/" "-"}}.{{$.Domain}}" {{end}} \ No newline at end of file diff --git a/templates/configuration.tmpl b/templates/configuration.tmpl index 4f5eed9bf..77f50dec0 100644 --- a/templates/configuration.tmpl +++ b/templates/configuration.tmpl @@ -23,6 +23,37 @@
+ +
+ + {{range $keyFrontends, $valueFrontends := .Configuration.Frontends}} +
+
{{$keyFrontends}}
+ + + + + + + + {{range $keyRoutes, $valueRoutes := $valueFrontends.Routes}} + + + + + + {{end}} +
RouteCategoryValue
{{$keyRoutes}}{{$valueRoutes.Category}}{{$valueRoutes.Value}}
+
+ {{end}} + +
@@ -48,37 +79,6 @@
-
- - {{range $keyRoutes, $valueRoutes := .Configuration.Routes}} -
-
{{$keyRoutes}}
- - - - - - - - {{range $keyRules, $valueRules := $valueRoutes.Rules}} - - - - - - {{end}} -
RuleCategoryValue
{{$keyRules}}{{$valueRules.Category}}{{$valueRules.Value}}
-
- {{end}} - -
-
diff --git a/traefik.go b/traefik.go index 91030f2e5..db4472eac 100644 --- a/traefik.go +++ b/traefik.go @@ -182,29 +182,29 @@ func LoadConfig(configuration *Configuration, gloablConfiguration *GlobalConfigu router := mux.NewRouter() router.NotFoundHandler = http.HandlerFunc(notFoundHandler) backends := map[string]http.Handler{} - for routeName, route := range configuration.Routes { - log.Debug("Creating route %s", routeName) + for frontendName, frontend := range configuration.Frontends { + log.Debug("Creating frontend %s", frontendName) fwd, _ := forward.New() newRoute := router.NewRoute() - for ruleName, rule := range route.Rules { - log.Debug("Creating rule %s", ruleName) - newRouteReflect := Invoke(newRoute, rule.Category, rule.Value) + for routeName, route := range frontend.Routes { + log.Debug("Creating route %s", routeName) + newRouteReflect := Invoke(newRoute, route.Category, route.Value) newRoute = newRouteReflect[0].Interface().(*mux.Route) } - if backends[route.Backend] == nil { - log.Debug("Creating backend %s", route.Backend) + if backends[frontend.Backend] == nil { + log.Debug("Creating backend %s", frontend.Backend) lb, _ := roundrobin.New(fwd) rb, _ := roundrobin.NewRebalancer(lb) - for serverName, server := range configuration.Backends[route.Backend].Servers { + for serverName, server := range configuration.Backends[frontend.Backend].Servers { log.Debug("Creating server %s", serverName) url, _ := url.Parse(server.Url) rb.UpsertServer(url, roundrobin.Weight(server.Weight)) } - backends[route.Backend] = lb + backends[frontend.Backend] = lb } else { - log.Debug("Reusing backend %s", route.Backend) + log.Debug("Reusing backend %s", frontend.Backend) } - newRoute.Handler(backends[route.Backend]) + newRoute.Handler(backends[frontend.Backend]) err := newRoute.GetError() if err != nil { log.Error("Error building route ", err) diff --git a/traefik.sample.toml b/traefik.sample.toml index cdce19ef9..fd5766ddb 100644 --- a/traefik.sample.toml +++ b/traefik.sample.toml @@ -192,14 +192,14 @@ # url = "http://172.17.0.5:80" # weight = 2 # -# [routes] -# [routes.route1] +# [frontends] +# [frontends.frontend1] # backend = "backend2" -# [routes.route1.rules.test_1] +# [frontends.frontend1.routes.test_1] # category = "Host" # value = "test.localhost" -# [routes.route2] +# [frontends.frontend2] # backend = "backend1" -# [routes.route2.rules.test_2] +# [frontends.frontend2.routes.test_2] # category = "Path" # value = "/test" diff --git a/traefik.toml b/traefik.toml index 43a7dadee..3de4d6006 100644 --- a/traefik.toml +++ b/traefik.toml @@ -192,14 +192,14 @@ domain = "docker.localhost" # url = "http://172.17.0.5:80" # weight = 2 # -# [routes] -# [routes.route1] +# [frontends] +# [frontends.frontend1] # backend = "backend2" -# [routes.route1.rules.test_1] +# [frontends.frontend1.routes.test_1] # category = "Host" # value = "test.localhost" -# [routes.route2] +# [frontends.frontend2] # backend = "backend1" -# [routes.route2.rules.test_2] +# [frontends.frontend2.routes.test_2] # category = "Path" # value = "/test"