问题1:
func main() {
model.DBNew("./conf.toml")
var user []model.CoreGrained
model.DB().Find(&user)
for _, i := range user {
var gg []string
err := json.Unmarshal(i.Group, &gg)
if err != nil {
log.Print(err)
}
fmt.Println(gg) //看这里的顺序
for _, v := range gg {
for _, vv := range strings.TrimSpace(v) {
if vv == 'B' { //不匹配
fmt.Println("true")
return
}
}
}
}
}
运行结果:
/mnt/c/Users/Administrator/AppData/Local/Temp/GoLand/___75go_build_TestPrt_go_linux
[ admin]
[c051d777-5c41-4e7d-9379-2054851803c4]
问题2
func main() {
model.DBNew("./conf.toml")
var user []model.CoreGrained
model.DB().Find(&user)
for _, i := range user {
var gg []string
err := json.Unmarshal(i.Group, &gg)
if err != nil {
log.Print(err)
}
fmt.Println(gg)
for _, v := range gg {
for _, vv := range strings.TrimSpace(v) {
if vv == 'a' { //关键是这里 ,匹配
fmt.Println("true")
return
}
}
}
}
}
/mnt/c/Users/Administrator/AppData/Local/Temp/GoLand/___291go_build_TestPrt_go_linux
[ admin] //只打印一个admin,?执行顺序被颠倒
true
问题3
func main() {
model.DBNew("./conf.toml")
var user []model.CoreGrained
model.DB().Find(&user)
for _, i := range user {
var gg []string
err := json.Unmarshal(i.Group, &gg)
if err != nil {
log.Print(err)
}
fmt.Println(gg)
for _, v := range gg {
for _, vv := range strings.TrimSpace(v) {
if vv == 'c' { //匹配
fmt.Println("true")
return
}
}
}
}
}
/mnt/c/Users/Administrator/AppData/Local/Temp/GoLand/___111go_build_TestPrt_go_linux
[ admin]
[c051d777-5c41-4e7d-9379-2054851803c4]
true
标签:err,fmt,打印,gg,range,user,Println,model From: https://www.cnblogs.com/cheyunhua/p/17062543.html