-
Notifications
You must be signed in to change notification settings - Fork 0
/
reload.go
52 lines (41 loc) · 916 Bytes
/
reload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package reloading_router
import (
"log"
"net/http"
"time"
"github.com/realbucksavage/stargate"
)
func main() {
l := customLister{
Routes: map[string][]string{
"/test": {"http://localhost:8081"},
"/ds_1": {"http://localhost:8082"},
},
}
sg, err := stargate.NewRouter(&l)
if err != nil {
log.Fatal(err)
}
go func() {
time.Sleep(time.Second * 25)
l.changeRoutes()
sg.Reload()
}()
log.Println("Starting server...")
log.Fatal(http.ListenAndServe(":7000", sg))
}
type customLister struct {
Routes map[string][]string
}
func (c *customLister) List(route string) ([]string, error) {
return c.Routes[route], nil
}
func (c *customLister) ListAll() (map[string][]string, error) {
return c.Routes, nil
}
func (c *customLister) changeRoutes() {
c.Routes = map[string][]string{
"/": {"http://localhost:8082", "http://localhost:8083"},
"/ds_2": {"http://localhost:8081"},
}
}