toml config
This commit is contained in:
parent
3680c8dc60
commit
c460f3abcd
2 changed files with 66 additions and 8 deletions
55
tortuous.go
55
tortuous.go
|
@ -5,17 +5,52 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"github.com/wunderlist/moxy"
|
"github.com/mailgun/oxy/forward"
|
||||||
|
"github.com/mailgun/oxy/roundrobin"
|
||||||
|
"github.com/mailgun/oxy/testutils"
|
||||||
"time"
|
"time"
|
||||||
"net"
|
"net"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
"github.com/BurntSushi/toml"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Backend struct {
|
||||||
|
Name string
|
||||||
|
Servers []string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Server struct {
|
||||||
|
Name string
|
||||||
|
Url string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Rule struct {
|
||||||
|
Category string
|
||||||
|
Value string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Route struct {
|
||||||
|
Name string
|
||||||
|
Rules map[string]Rule
|
||||||
|
}
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Backends []Backend
|
||||||
|
Servers []Server
|
||||||
|
Routes []Route
|
||||||
|
}
|
||||||
|
|
||||||
var srv *graceful.Server
|
var srv *graceful.Server
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Tortuous loading with pid", os.Getpid())
|
|
||||||
|
var config Config
|
||||||
|
if _, err := toml.DecodeFile("tortuous.toml", &config); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("%+v\n", config )
|
||||||
|
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
@ -23,14 +58,18 @@ func main() {
|
||||||
systemRouter := mux.NewRouter()
|
systemRouter := mux.NewRouter()
|
||||||
systemRouter.Methods("POST").Path("/").HandlerFunc(ReloadHandler)
|
systemRouter.Methods("POST").Path("/").HandlerFunc(ReloadHandler)
|
||||||
systemRouter.Methods("GET").Path("/").HandlerFunc(GetPidHandler)
|
systemRouter.Methods("GET").Path("/").HandlerFunc(GetPidHandler)
|
||||||
|
go http.ListenAndServe(":8000", systemRouter)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
fwd, _ := forward.New()
|
||||||
|
lb, _ := roundrobin.New(fwd)
|
||||||
|
|
||||||
|
lb.UpsertServer(testutils.ParseURI("http://172.17.0.2:80"))
|
||||||
|
lb.UpsertServer(testutils.ParseURI("http://172.17.0.3:80"))
|
||||||
|
|
||||||
userRouter := mux.NewRouter()
|
userRouter := mux.NewRouter()
|
||||||
hosts := []string{"172.17.0.2"}
|
userRouter.Host("test.zenika.fr").Handler(lb)
|
||||||
filters := []moxy.FilterFunc{}
|
|
||||||
proxy := moxy.NewReverseProxy(hosts, filters)
|
|
||||||
userRouter.Host("test.zenika.fr").HandlerFunc(proxy.ServeHTTP)
|
|
||||||
|
|
||||||
go http.ListenAndServe(":8000", systemRouter)
|
|
||||||
|
|
||||||
goAway := false
|
goAway := false
|
||||||
go func() {
|
go func() {
|
||||||
|
|
19
tortuous.toml
Normal file
19
tortuous.toml
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
[[backends]]
|
||||||
|
name = "backend1"
|
||||||
|
servers = ["server1", "server2"]
|
||||||
|
|
||||||
|
[[servers]]
|
||||||
|
name = "server1"
|
||||||
|
url = "http://172.17.0.2:80"
|
||||||
|
|
||||||
|
[[servers]]
|
||||||
|
name = "server2"
|
||||||
|
url = "http://172.17.0.3:80"
|
||||||
|
|
||||||
|
[[routes]]
|
||||||
|
name = "route1"
|
||||||
|
backends = ["backend1"]
|
||||||
|
[[rules]]
|
||||||
|
[[rules.1]]
|
||||||
|
category = "Host"
|
||||||
|
value = "test.zenika.fr"
|
Loading…
Reference in a new issue