/
main.go
63 lines (50 loc) · 1.07 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
package client
import (
"github.com/kilgaloon/leprechaun/log"
"fmt"
"github.com/fsnotify/fsnotify"
"io/ioutil"
"time"
)
// Client settings and configurations
type Client struct {
Config *Config
Logs log.Logs
}
// Start runs server
func Start(iniPath *string) {
var client = &Client{}
// load configurations for server
client.Config = readConfig(*iniPath)
files, err := ioutil.ReadDir(client.Config.recipesPath)
if err != nil {
client.Logs.Error("%s", err)
}
q := BuildQueue(client.Config.recipesPath, files)
// watch for new recipes
watcher, err := fsnotify.NewWatcher()
if err != nil {
client.Logs.Error("Failed to create watcher")
}
defer watcher.Close()
go func() {
for {
select {
case event := <-watcher.Events:
if event.Op&fsnotify.Create == fsnotify.Create {
AddToQueue(&q.Stack, event.Name)
}
case err := <-watcher.Errors:
fmt.Println("error:", err)
}
}
}()
err = watcher.Add(client.Config.recipesPath)
if err != nil {
fmt.Println(err)
}
for {
go ProcessQueue(&q, client)
time.Sleep(60 * time.Second)
}
}