mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-19 05:25:43 +00:00
chore: add enable metric flag
This commit is contained in:
parent
38cd5fabee
commit
2771602e5c
@ -31,6 +31,7 @@ var (
|
|||||||
data string
|
data string
|
||||||
driver string
|
driver string
|
||||||
dsn string
|
dsn string
|
||||||
|
enableMetric bool
|
||||||
|
|
||||||
rootCmd = &cobra.Command{
|
rootCmd = &cobra.Command{
|
||||||
Use: "slash",
|
Use: "slash",
|
||||||
@ -57,8 +58,10 @@ var (
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if serverProfile.Metric {
|
||||||
// nolint
|
// nolint
|
||||||
metric.NewMetricClient(s.Secret, *serverProfile)
|
metric.NewMetricClient(s.Secret, *serverProfile)
|
||||||
|
}
|
||||||
|
|
||||||
c := make(chan os.Signal, 1)
|
c := make(chan os.Signal, 1)
|
||||||
// Trigger graceful shutdown on SIGINT or SIGTERM.
|
// Trigger graceful shutdown on SIGINT or SIGTERM.
|
||||||
@ -100,6 +103,7 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().StringVarP(&data, "data", "d", "", "data directory")
|
rootCmd.PersistentFlags().StringVarP(&data, "data", "d", "", "data directory")
|
||||||
rootCmd.PersistentFlags().StringVarP(&driver, "driver", "", "", "database driver")
|
rootCmd.PersistentFlags().StringVarP(&driver, "driver", "", "", "database driver")
|
||||||
rootCmd.PersistentFlags().StringVarP(&dsn, "dsn", "", "", "database source name(aka. DSN)")
|
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"))
|
err := viper.BindPFlag("mode", rootCmd.PersistentFlags().Lookup("mode"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -121,10 +125,15 @@ func init() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
err = viper.BindPFlag("metric", rootCmd.PersistentFlags().Lookup("metric"))
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
viper.SetDefault("mode", "demo")
|
viper.SetDefault("mode", "demo")
|
||||||
viper.SetDefault("port", 8082)
|
viper.SetDefault("port", 8082)
|
||||||
viper.SetDefault("driver", "sqlite")
|
viper.SetDefault("driver", "sqlite")
|
||||||
|
viper.SetDefault("metric", true)
|
||||||
viper.SetEnvPrefix("slash")
|
viper.SetEnvPrefix("slash")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,6 +152,7 @@ func initConfig() {
|
|||||||
println("port:", serverProfile.Port)
|
println("port:", serverProfile.Port)
|
||||||
println("mode:", serverProfile.Mode)
|
println("mode:", serverProfile.Mode)
|
||||||
println("version:", serverProfile.Version)
|
println("version:", serverProfile.Version)
|
||||||
|
println("metric:", serverProfile.Metric)
|
||||||
println("---")
|
println("---")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ type Profile struct {
|
|||||||
Driver string `json:"-"`
|
Driver string `json:"-"`
|
||||||
// Version is the current version of server
|
// Version is the current version of server
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
|
// Metric indicate the metric collection is enabled or not
|
||||||
|
Metric bool `json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Profile) IsDev() bool {
|
func (p *Profile) IsDev() bool {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user