-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
47 lines (38 loc) · 878 Bytes
/
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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"regexp"
log "github.com/sirupsen/logrus"
)
func main() {
configDirectory := "./bots"
files, err := ioutil.ReadDir(configDirectory)
if err != nil {
log.Fatal(err)
}
r, _ := regexp.Compile(`\.json$`)
for _, file := range files {
if !file.IsDir() && r.FindString(file.Name()) != "" && file.Name() != "sample.json" {
fileFullPath := fmt.Sprintf("%s/%s", configDirectory, file.Name())
createTicker(fileFullPath)
}
}
for {
select {}
}
}
func createTicker(jsonFilePath string) {
log.Infoln("Loading ticker from: ", jsonFilePath)
jsonBytes, err := ioutil.ReadFile(jsonFilePath)
if err != nil {
log.Errorf("Error reading json file: ", err)
}
ticker := Ticker{}
err = json.Unmarshal(jsonBytes, &ticker)
if err != nil {
log.Errorf("Error loading ticker: ", err)
}
go ticker.run()
}