-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathconfig_lint.go
54 lines (45 loc) · 1.34 KB
/
config_lint.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
//nolint:dupl
package cmd
import (
"log"
"github.com/gatewayd-io/gatewayd/config"
"github.com/getsentry/sentry-go"
"github.com/spf13/cobra"
)
// configLintCmd represents the config lint command.
var configLintCmd = &cobra.Command{
Use: "lint",
Short: "Lint the GatewayD global config",
Run: func(cmd *cobra.Command, _ []string) {
enableSentry, _ := cmd.Flags().GetBool("sentry")
globalConfigFile, _ := cmd.Flags().GetString("config")
// Enable Sentry.
if enableSentry {
// Initialize Sentry.
err := sentry.Init(sentry.ClientOptions{
Dsn: DSN,
TracesSampleRate: config.DefaultTraceSampleRate,
AttachStacktrace: config.DefaultAttachStacktrace,
})
if err != nil {
cmd.Println("Sentry initialization failed: ", err)
return
}
// Flush buffered events before the program terminates.
defer sentry.Flush(config.DefaultFlushTimeout)
// Recover from panics and report the error to Sentry.
defer sentry.Recover()
}
if err := lintConfig(Global, globalConfigFile); err != nil {
log.Fatal(err)
}
cmd.Println("global config is valid")
},
}
func init() {
configCmd.AddCommand(configLintCmd)
configLintCmd.Flags().StringP(
"config", "c", config.GetDefaultConfigFilePath(config.GlobalConfigFilename),
"Global config file")
configLintCmd.Flags().Bool("sentry", true, "Enable Sentry")
}