go-判断字符串是否包含在数组中

判断数组中是否包含某字符串

1
2
3
4
5
6
7
8
func IsContain(items []string, item string) bool {
for _, eachItem := range items {
if eachItem == item {
return true
}
}
return false
}
1
2
3
if IsContain(fip.Tags,"router_forward"){
portForwardFips += 1
}

推荐使用

1
2
3
4
import github.com/robin5911/gtools/slice

isHas := slice.CheckIsContain(SLICE,"e451f79c-f4ab-4c3a-b895-288bc60c2c5b")
fmt.Println(isHas)