在写 Go 程序时报了一个莫名的错误,如标题。
仔细排查后发现问题出在这个块代码
1 | rows, err := db.Query(query, args...) |
经过 Google 后发现,defer
的位置不正确
The defer only defers the function call. The field and method are accessed immediately.
修改后即可
1 | rows, err := db.Query(query, args...) |
最近热读
扫码关注公众号,或搜索公众号“温欣爸比”
及时获取我的最新文章
