Skip to content

Commit 653b094

Browse files
committed
refactor: refactor configuration to add and apply comprehensive defaults
- Rename setDefault to setDefaults and refactor to set a comprehensive list of default configuration values for various modules (core, iOS, Android, gRPC, queue, stat) - Add many new default settings, including fields for SSL, PID, auto TLS, and engine types - Update config loader to use new setDefaults function Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent 8ea3308 commit 653b094

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

config/config.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,53 @@ type SectionGRPC struct {
312312
Port string `yaml:"port"`
313313
}
314314

315-
func setDefault() {
315+
func setDefaults() {
316+
// Core defaults
317+
viper.SetDefault("core.enabled", true)
318+
viper.SetDefault("core.address", "")
319+
viper.SetDefault("core.shutdown_timeout", 30)
320+
viper.SetDefault("core.port", "8088")
321+
viper.SetDefault("core.worker_num", 0)
322+
viper.SetDefault("core.queue_num", 0)
323+
viper.SetDefault("core.max_notification", 100)
324+
viper.SetDefault("core.sync", false)
325+
viper.SetDefault("core.feedback_timeout", 10)
326+
viper.SetDefault("core.mode", "release")
327+
viper.SetDefault("core.ssl", false)
328+
viper.SetDefault("core.cert_path", "cert.pem")
329+
viper.SetDefault("core.key_path", "key.pem")
330+
viper.SetDefault("core.pid.enabled", false)
331+
viper.SetDefault("core.pid.path", "gorush.pid")
332+
viper.SetDefault("core.pid.override", true)
333+
viper.SetDefault("core.auto_tls.enabled", false)
334+
viper.SetDefault("core.auto_tls.folder", ".cache")
335+
336+
// iOS defaults
337+
viper.SetDefault("ios.enabled", false)
338+
viper.SetDefault("ios.key_type", "pem")
339+
viper.SetDefault("ios.production", false)
316340
viper.SetDefault("ios.max_concurrent_pushes", uint(100))
341+
viper.SetDefault("ios.max_retry", 0)
342+
343+
// Android defaults
344+
viper.SetDefault("android.enabled", true)
345+
viper.SetDefault("android.max_retry", 0)
346+
347+
// gRPC defaults
348+
viper.SetDefault("grpc.enabled", false)
349+
viper.SetDefault("grpc.port", "9000")
350+
351+
// Queue defaults
352+
viper.SetDefault("queue.engine", "local")
353+
354+
// Stat defaults
355+
viper.SetDefault("stat.engine", "memory")
317356
}
318357

319358
// LoadConf load config from file and read in environment variables that match
320359
func LoadConf(confPath ...string) (*ConfYaml, error) {
321360
// load default values
322-
setDefault()
361+
setDefaults()
323362

324363
viper.SetConfigType("yaml")
325364
viper.AutomaticEnv() // read in environment variables that match

0 commit comments

Comments
 (0)