Remove redundant nil checks in system connection remove

From the Go specification:

  "3. If the map is nil, the number of iterations is 0." [1]

Therefore, an additional nil check for before the loop is unnecessary.

[NO NEW TESTS NEEDED]

[1]: https://go.dev/ref/spec#For_range

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
This commit is contained in:
Eng Zer Jun
2023-09-02 20:18:42 +08:00
parent 1361fa2304
commit f094884c1b

View File

@ -54,19 +54,15 @@ func rm(cmd *cobra.Command, args []string) error {
} }
if rmOpts.All { if rmOpts.All {
if cfg.Engine.ServiceDestinations != nil {
for k := range cfg.Engine.ServiceDestinations { for k := range cfg.Engine.ServiceDestinations {
delete(cfg.Engine.ServiceDestinations, k) delete(cfg.Engine.ServiceDestinations, k)
} }
}
cfg.Engine.ActiveService = "" cfg.Engine.ActiveService = ""
// Clear all the connections in any existing farms // Clear all the connections in any existing farms
if cfg.Farms.List != nil {
for k := range cfg.Farms.List { for k := range cfg.Farms.List {
cfg.Farms.List[k] = []string{} cfg.Farms.List[k] = []string{}
} }
}
return cfg.Write() return cfg.Write()
} }
@ -83,14 +79,12 @@ func rm(cmd *cobra.Command, args []string) error {
} }
// If there are existing farm, remove the deleted connection that might be part of a farm // If there are existing farm, remove the deleted connection that might be part of a farm
if cfg.Farms.List != nil {
for k, v := range cfg.Farms.List { for k, v := range cfg.Farms.List {
index := util.IndexOfStringInSlice(args[0], v) index := util.IndexOfStringInSlice(args[0], v)
if index > -1 { if index > -1 {
cfg.Farms.List[k] = append(v[:index], v[index+1:]...) cfg.Farms.List[k] = append(v[:index], v[index+1:]...)
} }
} }
}
return cfg.Write() return cfg.Write()
} }