Ver código fonte

Use logrus to panic on err + localise variables

Brendan Abolivier 6 anos atrás
pai
commit
7682350a35
Assinado por: Brendan Abolivier <contact@brendanabolivier.com> ID da chave GPG: 8EF1500759F70623
2 arquivos alterados com 12 adições e 12 exclusões
  1. 4
    2
      src/puller/main.go
  2. 8
    10
      src/pusher/main.go

+ 4
- 2
src/puller/main.go Ver arquivo

@@ -6,6 +6,8 @@ import (
6 6
 	"config"
7 7
 	"grafana"
8 8
 	"logger"
9
+
10
+	"github.com/sirupsen/logrus"
9 11
 )
10 12
 
11 13
 func main() {
@@ -16,11 +18,11 @@ func main() {
16 18
 
17 19
 	cfg, err := config.Load(*configFile)
18 20
 	if err != nil {
19
-		panic(err)
21
+		logrus.Panic(err)
20 22
 	}
21 23
 
22 24
 	client := grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey)
23 25
 	if err := PullGrafanaAndCommit(client, cfg); err != nil {
24
-		panic(err)
26
+		logrus.Panic(err)
25 27
 	}
26 28
 }

+ 8
- 10
src/pusher/main.go Ver arquivo

@@ -6,14 +6,12 @@ import (
6 6
 	"config"
7 7
 	"grafana"
8 8
 	"logger"
9
+	"pusher/webhook"
10
+
11
+	"github.com/sirupsen/logrus"
9 12
 )
10 13
 
11
-// Some variables need to be global to the package since we need them in the
12
-// webhook handlers.
13
-// TODO: Find a better way to pass it to the handlers
14 14
 var (
15
-	grafanaClient *grafana.Client
16
-	cfg           *config.Config
17 15
 	deleteRemoved = flag.Bool("delete-removed", false, "For each file removed from Git, delete the corresponding dashboard on the Grafana API")
18 16
 )
19 17
 
@@ -25,14 +23,14 @@ func main() {
25 23
 
26 24
 	logger.LogConfig()
27 25
 
28
-	cfg, err = config.Load(*configFile)
26
+	cfg, err := config.Load(*configFile)
29 27
 	if err != nil {
30
-		panic(err)
28
+		logrus.Panic(err)
31 29
 	}
32 30
 
33
-	grafanaClient = grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey)
31
+	grafanaClient := grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey)
34 32
 
35
-	if err = SetupWebhook(cfg); err != nil {
36
-		panic(err)
33
+	if err = webhook.Setup(cfg, grafanaClient, *deleteRemoved); err != nil {
34
+		logrus.Panic(err)
37 35
 	}
38 36
 }