From c28e8a23972949fa8aefd018502885a115f5e51a Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Thu, 6 Dec 2018 00:44:41 -0800 Subject: [PATCH] refactoring --- weed/command/filer_replication.go | 24 ++++++++++++++---------- weed/filer2/configuration.go | 24 ++++++++++++++---------- weed/notification/configuration.go | 24 ++++++++++++++---------- 3 files changed, 42 insertions(+), 30 deletions(-) diff --git a/weed/command/filer_replication.go b/weed/command/filer_replication.go index 087a12059..3384e4023 100644 --- a/weed/command/filer_replication.go +++ b/weed/command/filer_replication.go @@ -41,16 +41,7 @@ func runFilerReplicate(cmd *Command, args []string) bool { var notificationInput sub.NotificationInput - enabledInput := "" - for _, input := range sub.NotificationInputs { - if config.GetBool("notification." + input.GetName() + ".enabled") { - if enabledInput == "" { - enabledInput = input.GetName() - } else { - glog.Fatalf("Notification input is enabled for both %s and %s", enabledInput, input.GetName()) - } - } - } + validateOneEnabledInput(config) for _, input := range sub.NotificationInputs { if config.GetBool("notification." + input.GetName() + ".enabled") { @@ -133,3 +124,16 @@ func runFilerReplicate(cmd *Command, args []string) bool { return true } + +func validateOneEnabledInput(config *viper.Viper) { + enabledInput := "" + for _, input := range sub.NotificationInputs { + if config.GetBool("notification." + input.GetName() + ".enabled") { + if enabledInput == "" { + enabledInput = input.GetName() + } else { + glog.Fatalf("Notification input is enabled for both %s and %s", enabledInput, input.GetName()) + } + } + } +} diff --git a/weed/filer2/configuration.go b/weed/filer2/configuration.go index 4b20b608b..7b05b53dc 100644 --- a/weed/filer2/configuration.go +++ b/weed/filer2/configuration.go @@ -13,16 +13,7 @@ var ( func (f *Filer) LoadConfiguration(config *viper.Viper) { - enabledStore := "" - for _, store := range Stores { - if config.GetBool(store.GetName() + ".enabled") { - if enabledStore == "" { - enabledStore = store.GetName() - } else { - glog.Fatalf("Filer store is enabled for both %s and %s", enabledStore, store.GetName()) - } - } - } + validateOneEnabledStore(config) for _, store := range Stores { if config.GetBool(store.GetName() + ".enabled") { @@ -45,3 +36,16 @@ func (f *Filer) LoadConfiguration(config *viper.Viper) { os.Exit(-1) } + +func validateOneEnabledStore(config *viper.Viper) { + enabledStore := "" + for _, store := range Stores { + if config.GetBool(store.GetName() + ".enabled") { + if enabledStore == "" { + enabledStore = store.GetName() + } else { + glog.Fatalf("Filer store is enabled for both %s and %s", enabledStore, store.GetName()) + } + } + } +} diff --git a/weed/notification/configuration.go b/weed/notification/configuration.go index f34ccf305..7f8765cc3 100644 --- a/weed/notification/configuration.go +++ b/weed/notification/configuration.go @@ -27,16 +27,7 @@ func LoadConfiguration(config *viper.Viper) { return } - enabledQueue := "" - for _, queue := range MessageQueues { - if config.GetBool(queue.GetName() + ".enabled") { - if enabledQueue == "" { - enabledQueue = queue.GetName() - } else { - glog.Fatalf("Notification message queue is enabled for both %s and %s", enabledQueue, queue.GetName()) - } - } - } + validateOneEnabledQueue(config) for _, queue := range MessageQueues { if config.GetBool(queue.GetName() + ".enabled") { @@ -52,3 +43,16 @@ func LoadConfiguration(config *viper.Viper) { } } + +func validateOneEnabledQueue(config *viper.Viper) { + enabledQueue := "" + for _, queue := range MessageQueues { + if config.GetBool(queue.GetName() + ".enabled") { + if enabledQueue == "" { + enabledQueue = queue.GetName() + } else { + glog.Fatalf("Notification message queue is enabled for both %s and %s", enabledQueue, queue.GetName()) + } + } + } +}