-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (38 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
package main
import (
"flag"
"log"
"sync"
"rulent/handlers"
"rulent/models"
"github.com/gofiber/fiber/v2"
)
func main() {
configPathPtr := flag.String("config", "events.yaml", "path to config file")
flag.Parse() // Parse the flags
// Dereference the pointer to get the actual config path
configFilePath := *configPathPtr
app := fiber.New(fiber.Config{
ServerHeader: "Rulent Server",
})
config := models.Config{}
err := config.ParseConfig(configFilePath)
if err != nil {
log.Fatalf("Error parsing config file: %v", err)
}
errorChan := make(chan error)
var wg sync.WaitGroup
app.Post("/validate", handlers.ValidateHandler(&config, errorChan, &wg))
// Goroutine for handling errors from the asynchronous actions
go func() {
for err := range errorChan {
log.Printf("error from action: %v", err)
// Handle the error, e.g., by logging or sending a notification
}
}()
app.Get("/reload", handlers.ReloadHandler(&config, configFilePath))
log.Fatal(app.Listen(":8081"))
// Close the error channel when all goroutines are done
wg.Wait()
close(errorChan)
}