toml config with nested tables

This commit is contained in:
emile 2015-09-01 22:56:43 +02:00
parent c460f3abcd
commit b5828f89e2
2 changed files with 22 additions and 24 deletions

View file

@ -16,12 +16,10 @@ import (
)
type Backend struct {
Name string
Servers []string
}
type Server struct {
Name string
Url string
}
@ -31,14 +29,14 @@ type Rule struct {
}
type Route struct {
Name string
Backends []string
Rules map[string]Rule
}
type Config struct {
Backends []Backend
Servers []Server
Routes []Route
Backends map[string]Backend
Servers map[string]Server
Routes map[string]Route
}
var srv *graceful.Server
@ -60,7 +58,11 @@ func main() {
systemRouter.Methods("GET").Path("/").HandlerFunc(GetPidHandler)
go http.ListenAndServe(":8000", systemRouter)
userRouter := mux.NewRouter()
/*for i := range config.Routes {
fmt.Printf("%+v\n", config.Routes[i] )
}*/
fwd, _ := forward.New()
lb, _ := roundrobin.New(fwd)
@ -68,7 +70,6 @@ func main() {
lb.UpsertServer(testutils.ParseURI("http://172.17.0.2:80"))
lb.UpsertServer(testutils.ParseURI("http://172.17.0.3:80"))
userRouter := mux.NewRouter()
userRouter.Host("test.zenika.fr").Handler(lb)
goAway := false

View file

@ -1,19 +1,16 @@
[[backends]]
name = "backend1"
[backends]
[backends.backend1]
servers = ["server1", "server2"]
[[servers]]
name = "server1"
[servers]
[servers.server1]
url = "http://172.17.0.2:80"
[[servers]]
name = "server2"
[servers.server2]
url = "http://172.17.0.3:80"
[[routes]]
name = "route1"
[routes]
[routes.route1]
backends = ["backend1"]
[[rules]]
[[rules.1]]
[routes.route1.rules.test_zenika]
category = "Host"
value = "test.zenika.fr"