refactor: remove redundant len check (#1743)

`len` returns 0 if the slice is nil. From the Go specification [1]:

  "1. For a nil slice, the number of iterations is 0."

Therefore, an additional `len(v) != 0` check for before the loop is
unnecessary.

[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-26 17:00:05 +08:00
committed by GitHub
parent b43c1b9984
commit c1854a3a7b
4 changed files with 39 additions and 47 deletions

View File

@@ -138,14 +138,12 @@ func (c TOMLLoader) Load(pathToToml string) error {
if len(server.Enablerepo) == 0 {
server.Enablerepo = Conf.Default.Enablerepo
}
if len(server.Enablerepo) != 0 {
for _, repo := range server.Enablerepo {
switch repo {
case "base", "updates":
// nop
default:
return xerrors.Errorf("For now, enablerepo have to be base or updates: %s", server.Enablerepo)
}
for _, repo := range server.Enablerepo {
switch repo {
case "base", "updates":
// nop
default:
return xerrors.Errorf("For now, enablerepo have to be base or updates: %s", server.Enablerepo)
}
}