mySQL 查询函数返回一个行数组,定义为
type Row []interface{}
Run Code Online (Sandbox Code Playgroud)
我想检查返回的数组是否为空,但出现运行时恐慌:
s := fmt.Sprintf("select id, secret, shortname from beehives where shortname = '%s'", beehive)
rows, res, err := database.Query(s)
if err == nil {
if len(rows) != 1 {
Run Code Online (Sandbox Code Playgroud)
如果行为空,表达式 len(rows) 似乎会导致运行时恐慌。
如何检查空数组?我也试过行 == 零,这也恐慌。