Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: add a flag to change metric switch (#2447)

Athurg Goothbfdb33f26b50
diff --git a/cmd/memos.go b/cmd/memos.go
index 388688dc3..f2f9b4654 100644
--- a/cmd/memos.go
+++ b/cmd/memos.go
@@ -32,13 +32,14 @@ const (
)
var (
- profile *_profile.Profile
- mode string
- addr string
- port int
- data string
- driver string
- dsn string
+ profile *_profile.Profile
+ mode string
+ addr string
+ port int
+ data string
+ driver string
+ dsn string
+ enableMetric bool
rootCmd = &cobra.Command{
Use: "memos",
@@ -65,8 +66,10 @@ var (
return
}
- // nolint
- metric.NewMetricClient(s.ID, *profile)
+ if enableMetric {
+ // nolint
+ metric.NewMetricClient(s.ID, *profile)
+ }
c := make(chan os.Signal, 1)
// Trigger graceful shutdown on SIGINT or SIGTERM.
@@ -109,6 +112,7 @@ func init() {
rootCmd.PersistentFlags().StringVarP(&data, "data", "d", "", "data directory")
rootCmd.PersistentFlags().StringVarP(&driver, "driver", "", "", "database driver")
rootCmd.PersistentFlags().StringVarP(&dsn, "dsn", "", "", "database source name(aka. DSN)")
+ rootCmd.PersistentFlags().BoolVarP(&enableMetric, "metric", "", true, "allow metric collection")
err := viper.BindPFlag("mode", rootCmd.PersistentFlags().Lookup("mode"))
if err != nil {
@@ -134,11 +138,16 @@ func init() {
if err != nil {
panic(err)
}
+ err = viper.BindPFlag("metric", rootCmd.PersistentFlags().Lookup("metric"))
+ if err != nil {
+ panic(err)
+ }
viper.SetDefault("mode", "demo")
viper.SetDefault("driver", "sqlite")
viper.SetDefault("addr", "")
viper.SetDefault("port", 8081)
+ viper.SetDefault("metric", "true")
viper.SetEnvPrefix("memos")
}