Browse Source

Comment main functions

Brendan Abolivier 6 years ago
parent
commit
5203f39154
Signed by: Brendan Abolivier <contact@brendanabolivier.com> GPG key ID: 8EF1500759F70623
2 changed files with 13 additions and 0 deletions
  1. 6
    0
      src/puller/main.go
  2. 7
    0
      src/pusher/main.go

+ 6
- 0
src/puller/main.go View File

11
 )
11
 )
12
 
12
 
13
 func main() {
13
 func main() {
14
+	// Define this flag in the main function because else it would cause a
15
+	// conflict with the one in the pusher.
14
 	configFile := flag.String("config", "config.yaml", "Path to the configuration file")
16
 	configFile := flag.String("config", "config.yaml", "Path to the configuration file")
15
 	flag.Parse()
17
 	flag.Parse()
16
 
18
 
19
+	// Load the logger's configuration.
17
 	logger.LogConfig()
20
 	logger.LogConfig()
18
 
21
 
22
+	// Load the configuration.
19
 	cfg, err := config.Load(*configFile)
23
 	cfg, err := config.Load(*configFile)
20
 	if err != nil {
24
 	if err != nil {
21
 		logrus.Panic(err)
25
 		logrus.Panic(err)
22
 	}
26
 	}
23
 
27
 
28
+	// Initialise the Grafana API client.
24
 	client := grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey)
29
 	client := grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey)
30
+	// Run the puller.
25
 	if err := PullGrafanaAndCommit(client, cfg); err != nil {
31
 	if err := PullGrafanaAndCommit(client, cfg); err != nil {
26
 		logrus.Panic(err)
32
 		logrus.Panic(err)
27
 	}
33
 	}

+ 7
- 0
src/pusher/main.go View File

19
 func main() {
19
 func main() {
20
 	var err error
20
 	var err error
21
 
21
 
22
+	// Define this flag in the main function because else it would cause a
23
+	// conflict with the one in the puller.
22
 	configFile := flag.String("config", "config.yaml", "Path to the configuration file")
24
 	configFile := flag.String("config", "config.yaml", "Path to the configuration file")
23
 	flag.Parse()
25
 	flag.Parse()
24
 
26
 
27
+	// Load the logger's configuration.
25
 	logger.LogConfig()
28
 	logger.LogConfig()
26
 
29
 
30
+	// Load the configuration.
27
 	cfg, err := config.Load(*configFile)
31
 	cfg, err := config.Load(*configFile)
28
 	if err != nil {
32
 	if err != nil {
29
 		logrus.Panic(err)
33
 		logrus.Panic(err)
30
 	}
34
 	}
31
 
35
 
36
+	// Initialise the Grafana API client.
32
 	grafanaClient := grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey)
37
 	grafanaClient := grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey)
33
 
38
 
39
+	// Set up either a webhook or a poller depending on the mode specified in the
40
+	// configuration file.
34
 	switch cfg.Pusher.Mode {
41
 	switch cfg.Pusher.Mode {
35
 	case "webhook":
42
 	case "webhook":
36
 		err = webhook.Setup(cfg, grafanaClient, *deleteRemoved)
43
 		err = webhook.Setup(cfg, grafanaClient, *deleteRemoved)