1
0
mirror of https://github.com/strongdm/comply synced 2024-11-26 17:44:53 +00:00
comply/internal/render/watch.go

52 lines
821 B
Go
Raw Normal View History

2018-05-15 21:13:11 +00:00
package render
import (
"net/http"
"time"
"github.com/gohugoio/hugo/watcher"
)
func watch(errCh chan error) {
// TODO: study about the poll duration
b, err := watcher.New(300 * time.Millisecond, 0, false)
2018-05-15 21:13:11 +00:00
if err != nil {
errCh <- err
return
}
b.Add("./templates/")
2018-05-17 00:27:01 +00:00
b.Add("./narratives/")
2018-05-15 21:13:11 +00:00
b.Add("./policies/")
b.Add("./procedures/")
b.Add("./.comply/")
b.Add("./.comply/cache")
b.Add("./.comply/cache/tickets")
go func() {
for {
select {
case e := <-b.Errors():
2018-05-15 21:13:11 +00:00
errCh <- e
case <-b.Events:
broadcast()
}
}
}()
serveWs := func(w http.ResponseWriter, r *http.Request) {
ws, err := upgrader.Upgrade(w, r, nil)
if err != nil {
errCh <- err
return
}
<-subscribe()
time.Sleep(500 * time.Millisecond)
ws.Close()
}
http.HandleFunc("/ws", serveWs)
return
}