The code looks like:
func Contain(livesJSON []LiveJSON, single db.Live) bool {
for _, json := range livesJSON {
if json.Start == single.Time && json.Team == single.HomeTeamId {
return false
} else {
return true
}
}
}
I have return
in both if
and else
.
There is no guarantee the loop body will be executed. This is the case if you pass nil
or an empty slice for livesJSON
. That way you would not return anything.
For that case, you must insert a return
statement after the loop:
func Contain(livesJSON []LiveJSON, single db.Live) bool {
for _, json := range livesJSON {
if json.Start == single.Time && json.Team == single.HomeTeamId {
return false
} else {
return true
}
}
return false
}