-
Notifications
You must be signed in to change notification settings - Fork 43
/
main.go
48 lines (40 loc) · 1.08 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
package controlplane
import (
"context"
"fmt"
"github.com/envoyproxy/go-control-plane/pkg/cache/v3"
serverv3 "github.com/envoyproxy/go-control-plane/pkg/server/v3"
"github.com/fsnotify/fsnotify"
log "github.com/sirupsen/logrus"
)
func Main(filename string, port uint, logger *log.Logger) {
snapshotCache := cache.NewSnapshotCache(false, cache.IDHash{}, logger)
proc := NewProcessor(snapshotCache, logger)
go func() {
ctx := context.Background()
server := serverv3.NewServer(ctx, snapshotCache, nil)
RunServer(ctx, server, port)
}()
notifyCh := make(chan NotifyMessage, 100)
notifyCh <- NotifyMessage{
Operation: Create,
FilePath: filename,
}
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(fmt.Errorf("failed to create file watcher, err: %v", err))
}
defer watcher.Close()
if err = watcher.Add(filename); err != nil {
log.Fatal(fmt.Errorf("failed to add file: %s to wather, err: %v", filename, err))
}
go func() {
log.Fatal(Watch(watcher, filename, notifyCh))
}()
for {
select {
case msg := <-notifyCh:
proc.ProcessFile(msg)
}
}
}