-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
82 lines (67 loc) · 1.66 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"github.com/SeleneSoftware/humboldt/controller"
"github.com/SeleneSoftware/humboldt/routetable"
"github.com/SeleneSoftware/humboldt/template"
// "context"
"fmt"
"github.com/radovskyb/watcher"
"github.com/yuin/gopher-lua"
"log"
"regexp"
"sync"
"time"
)
func main() {
httpServerExitDone := &sync.WaitGroup{}
httpServerExitDone.Add(1)
startHttpServer(httpServerExitDone)
L := lua.NewState()
defer L.Close()
L.PreloadModule("controller", controller.Loader)
L.PreloadModule("template", template.Loader)
L.PreloadModule("route", routetable.Loader)
w := watcher.New()
w.FilterOps(watcher.Rename, watcher.Move, watcher.Write)
if err := w.Add("Config"); err != nil {
log.Fatalln(err)
}
w.FilterOps(watcher.Create)
// Only files that match the regular expression during file listings
// will be watched.
r := regexp.MustCompile("^Routing.lua$")
w.AddFilterHook(watcher.RegexFilterHook(r, false))
go func() {
for {
select {
case event := <-w.Event:
fmt.Println(event)
// if err := srv.Shutdown(context.TODO()); err != nil {
// panic(err)
// }
if err := L.DoFile("Config/Routing.lua"); err != nil {
panic(err)
}
// httpServerExitDone = &sync.WaitGroup{}
//
// httpServerExitDone.Add(1)
// srv = startHttpServer(httpServerExitDone)
case err := <-w.Error:
log.Fatalln(err)
case <-w.Closed:
fmt.Println("Closed, foo!")
return
}
}
}()
for path, f := range w.WatchedFiles() {
fmt.Printf("%s: %s\n", path, f.Name())
}
go func() {
w.Wait()
w.TriggerEvent(watcher.Write, nil)
}()
if err := w.Start(time.Millisecond * 100); err != nil {
log.Fatalln(err)
}
}