refactor rules, api enhancements

This commit is contained in:
emile 2015-09-15 18:35:32 +02:00
parent a4f542c02f
commit ef9e773b9f
6 changed files with 8 additions and 8 deletions

View file

@ -35,7 +35,7 @@ type Server struct {
} }
type Route struct { type Route struct {
Category string Rule string
Value string Value string
} }

View file

@ -9,6 +9,6 @@
{{$container := index $containers 0}} {{$container := index $containers 0}}
backend = "backend-{{getBackend $container}}" backend = "backend-{{getBackend $container}}"
[frontends.frontend-{{$host}}.routes.route-host-{{$host}}] [frontends.frontend-{{$host}}.routes.route-host-{{$host}}]
category = "Host" rule = "Host"
value = "{{$host}}.{{$.Domain}}" value = "{{$host}}.{{$.Domain}}"
{{end}} {{end}}

View file

@ -14,6 +14,6 @@
[frontends.frontend{{.ID | replace "/" "-"}}] [frontends.frontend{{.ID | replace "/" "-"}}]
backend = "backend{{.ID | replace "/" "-"}}" backend = "backend{{.ID | replace "/" "-"}}"
[frontends.frontend-{{getHost . | replace "/" "-"}}.routes.route-host-{{getHost . | replace "/" "-"}}] [frontends.frontend-{{getHost . | replace "/" "-"}}.routes.route-host-{{getHost . | replace "/" "-"}}]
category = "Host" rule = "Host"
value = "{{getHost . | replace "/" "-"}}.{{$.Domain}}" value = "{{getHost . | replace "/" "-"}}.{{$.Domain}}"
{{end}} {{end}}

View file

@ -39,13 +39,13 @@
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
<tr> <tr>
<td><em>Route</em></td> <td><em>Route</em></td>
<td><em>Category</em></td> <td><em>Rule</em></td>
<td><em>Value</em></td> <td><em>Value</em></td>
</tr> </tr>
{{range $keyRoutes, $valueRoutes := $valueFrontends.Routes}} {{range $keyRoutes, $valueRoutes := $valueFrontends.Routes}}
<tr> <tr>
<td>{{$keyRoutes}}</td> <td>{{$keyRoutes}}</td>
<td>{{$valueRoutes.Category}}</td> <td>{{$valueRoutes.Rule}}</td>
<td>{{$valueRoutes.Value}}</td> <td>{{$valueRoutes.Value}}</td>
</tr> </tr>
{{end}} {{end}}

View file

@ -188,7 +188,7 @@ func LoadConfig(configuration *Configuration, gloablConfiguration *GlobalConfigu
newRoute := router.NewRoute() newRoute := router.NewRoute()
for routeName, route := range frontend.Routes { for routeName, route := range frontend.Routes {
log.Debug("Creating route %s", routeName) log.Debug("Creating route %s", routeName)
newRouteReflect := Invoke(newRoute, route.Category, route.Value) newRouteReflect := Invoke(newRoute, route.Rule, route.Value)
newRoute = newRouteReflect[0].Interface().(*mux.Route) newRoute = newRouteReflect[0].Interface().(*mux.Route)
} }
if backends[frontend.Backend] == nil { if backends[frontend.Backend] == nil {

View file

@ -196,10 +196,10 @@
# [frontends.frontend1] # [frontends.frontend1]
# backend = "backend2" # backend = "backend2"
# [frontends.frontend1.routes.test_1] # [frontends.frontend1.routes.test_1]
# category = "Host" # rule = "Host"
# value = "test.localhost" # value = "test.localhost"
# [frontends.frontend2] # [frontends.frontend2]
# backend = "backend1" # backend = "backend1"
# [frontends.frontend2.routes.test_2] # [frontends.frontend2.routes.test_2]
# category = "Path" # rule = "Path"
# value = "/test" # value = "/test"