-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
54 lines (45 loc) · 1.32 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
package main
import (
"flag"
"github.com/jasonlvhit/gocron"
"gopkg.in/go-playground/validator.v9"
)
var (
App *Application
Validator *validator.Validate
)
// Main execution
func main() {
migrate := flag.Bool("m", false, "Runs migrations before running server")
dbDriver := flag.String("driver", "sqlite3", "The database driver notify should use")
dbCreds := flag.String("creds", "/tmp/main.db", "The database credentials")
enableAlert := flag.Bool("a", false, "Enables the alerting schedule")
runAlert := flag.Bool("r", false, "Runs alerting straight away")
port := flag.String("port", ":8080", "Port on which the server runs")
user := flag.String("user", "admin", "Username for basic auth stuffs")
pass := flag.String("pass", "changeme", "Password for authentication")
flag.Parse()
App = NewApp(*port, *dbDriver, *dbCreds, *user, *pass)
// Run Migrations
if *migrate {
App.log.Debug("Running Migrations")
Migrate()
}
// Start the alert task schedule
if *enableAlert {
if *runAlert {
SendAlerts()
}
App.log.Debug("Starting Alert scheduler")
gocron.Every(1).Minute().Do(SendAlerts)
gocron.Start()
}
// Run The Application
App.Run()
}
// Runs the auto migrations for specific objects
func Migrate() {
App.db.AutoMigrate(&Tag{})
App.db.AutoMigrate(&Notification{})
App.db.AutoMigrate(&AlertGroup{})
}