-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
58 lines (49 loc) · 1.44 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
package main
import (
"dynamic-notification-system/config"
"dynamic-notification-system/notifier"
"dynamic-notification-system/plugins"
"dynamic-notification-system/scheduler"
"fmt"
"log"
"net/http"
"github.com/gorilla/mux"
)
func main() {
var err error
cfg, err := config.LoadConfig("config.yaml")
if err != nil {
log.Fatalf("Error loading config: %v", err)
}
// Load plugins based on configuration
notifiers, err := plugins.LoadPlugins(cfg.Channels)
if err != nil {
log.Fatalf("Error loading plugins: %v", err)
}
// Pass the loaded notifiers to the notifier package
notifier.SetNotifiers(notifiers)
// Initialize Scheduler if enabled
if cfg.Scheduler {
fmt.Println("Starting scheduled jobs...")
err = scheduler.Initialize(cfg, notifiers)
if err != nil {
log.Fatalf("Error initializing scheduler: %v", err)
}
defer scheduler.Shutdown()
} else {
fmt.Println("Scheduler is disabled in the configuration.")
}
r := mux.NewRouter()
if cfg.Scheduler {
// Scheduled notification endpoints
r.HandleFunc("/schema/job", scheduler.GetJobSchema())
r.HandleFunc("/jobs", scheduler.HandlePostJob).Methods("POST")
r.HandleFunc("/jobs", scheduler.HandleGetJobs).Methods("GET")
} else {
fmt.Println("Scheduling endpoints are disabled.")
}
// Instant notification endpoint
r.HandleFunc("/notify", notifier.HandlePostJob).Methods("POST")
fmt.Println("Server listening on port 8080")
log.Fatal(http.ListenAndServe(":8080", r))
}