From d27254c45a6b317d1b070351bef4b70959896fbc Mon Sep 17 00:00:00 2001 From: blight19 <37695262+blight19@users.noreply.github.com> Date: Wed, 6 Mar 2024 16:12:40 +0800 Subject: [PATCH] refactor: replace if-else with switch (#777) --- cmd/redis-shake/main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/redis-shake/main.go b/cmd/redis-shake/main.go index 0c98de9a..91ab37bc 100644 --- a/cmd/redis-shake/main.go +++ b/cmd/redis-shake/main.go @@ -34,7 +34,8 @@ func main() { // create reader var theReader reader.Reader - if v.IsSet("sync_reader") { + switch { + case v.IsSet("sync_reader"): opts := new(reader.SyncReaderOptions) defaults.SetDefaults(opts) err := v.UnmarshalKey("sync_reader", opts) @@ -48,7 +49,7 @@ func main() { theReader = reader.NewSyncStandaloneReader(ctx, opts) log.Infof("create SyncStandaloneReader: %v", opts.Address) } - } else if v.IsSet("scan_reader") { + case v.IsSet("scan_reader"): opts := new(reader.ScanReaderOptions) defaults.SetDefaults(opts) err := v.UnmarshalKey("scan_reader", opts) @@ -62,7 +63,7 @@ func main() { theReader = reader.NewScanStandaloneReader(ctx, opts) log.Infof("create ScanStandaloneReader: %v", opts.Address) } - } else if v.IsSet("rdb_reader") { + case v.IsSet("rdb_reader"): opts := new(reader.RdbReaderOptions) defaults.SetDefaults(opts) err := v.UnmarshalKey("rdb_reader", opts) @@ -71,7 +72,7 @@ func main() { } theReader = reader.NewRDBReader(opts) log.Infof("create RdbReader: %v", opts.Filepath) - } else if v.IsSet("aof_reader") { + case v.IsSet("aof_reader"): opts := new(reader.AOFReaderOptions) defaults.SetDefaults(opts) err := v.UnmarshalKey("aof_reader", opts) @@ -80,13 +81,13 @@ func main() { } theReader = reader.NewAOFReader(opts) log.Infof("create AOFReader: %v", opts.Filepath) - } else { + default: log.Panicf("no reader config entry found") } - // create writer var theWriter writer.Writer - if v.IsSet("redis_writer") { + switch { + case v.IsSet("redis_writer"): opts := new(writer.RedisWriterOptions) defaults.SetDefaults(opts) err := v.UnmarshalKey("redis_writer", opts) @@ -109,10 +110,9 @@ func main() { entry.Argv = []string{"FLUSHALL"} theWriter.Write(entry) } - } else { + default: log.Panicf("no writer config entry found") } - // create status status.Init(theReader, theWriter)