ソースを参照

Use logrus to panic on err + localise variables

Brendan Abolivier 6 年 前
コミット
7682350a35
署名者: Brendan Abolivier <contact@brendanabolivier.com> GPGキーID: 8EF1500759F70623
共有2 個のファイルを変更した12 個の追加12 個の削除を含む
  1. 4
    2
      src/puller/main.go
  2. 8
    10
      src/pusher/main.go

+ 4
- 2
src/puller/main.go ファイルの表示

6
 	"config"
6
 	"config"
7
 	"grafana"
7
 	"grafana"
8
 	"logger"
8
 	"logger"
9
+
10
+	"github.com/sirupsen/logrus"
9
 )
11
 )
10
 
12
 
11
 func main() {
13
 func main() {
16
 
18
 
17
 	cfg, err := config.Load(*configFile)
19
 	cfg, err := config.Load(*configFile)
18
 	if err != nil {
20
 	if err != nil {
19
-		panic(err)
21
+		logrus.Panic(err)
20
 	}
22
 	}
21
 
23
 
22
 	client := grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey)
24
 	client := grafana.NewClient(cfg.Grafana.BaseURL, cfg.Grafana.APIKey)
23
 	if err := PullGrafanaAndCommit(client, cfg); err != nil {
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 ファイルの表示

6
 	"config"
6
 	"config"
7
 	"grafana"
7
 	"grafana"
8
 	"logger"
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
 var (
14
 var (
15
-	grafanaClient *grafana.Client
16
-	cfg           *config.Config
17
 	deleteRemoved = flag.Bool("delete-removed", false, "For each file removed from Git, delete the corresponding dashboard on the Grafana API")
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
 
23
 
26
 	logger.LogConfig()
24
 	logger.LogConfig()
27
 
25
 
28
-	cfg, err = config.Load(*configFile)
26
+	cfg, err := config.Load(*configFile)
29
 	if err != nil {
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
 }