refactoring

This commit is contained in:
Chris Lu 2018-12-06 00:44:41 -08:00
parent ffa2827ab1
commit c28e8a2397
3 changed files with 42 additions and 30 deletions

View file

@ -41,16 +41,7 @@ func runFilerReplicate(cmd *Command, args []string) bool {
var notificationInput sub.NotificationInput var notificationInput sub.NotificationInput
enabledInput := "" validateOneEnabledInput(config)
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())
}
}
}
for _, input := range sub.NotificationInputs { for _, input := range sub.NotificationInputs {
if config.GetBool("notification." + input.GetName() + ".enabled") { if config.GetBool("notification." + input.GetName() + ".enabled") {
@ -133,3 +124,16 @@ func runFilerReplicate(cmd *Command, args []string) bool {
return true 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())
}
}
}
}

View file

@ -13,16 +13,7 @@ var (
func (f *Filer) LoadConfiguration(config *viper.Viper) { func (f *Filer) LoadConfiguration(config *viper.Viper) {
enabledStore := "" validateOneEnabledStore(config)
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())
}
}
}
for _, store := range Stores { for _, store := range Stores {
if config.GetBool(store.GetName() + ".enabled") { if config.GetBool(store.GetName() + ".enabled") {
@ -45,3 +36,16 @@ func (f *Filer) LoadConfiguration(config *viper.Viper) {
os.Exit(-1) 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())
}
}
}
}

View file

@ -27,16 +27,7 @@ func LoadConfiguration(config *viper.Viper) {
return return
} }
enabledQueue := "" validateOneEnabledQueue(config)
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())
}
}
}
for _, queue := range MessageQueues { for _, queue := range MessageQueues {
if config.GetBool(queue.GetName() + ".enabled") { 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())
}
}
}
}