问题描述
我目前有:
func foo (w http.ResponseWriter,req *http.Request) {
chekr := `SELECT FROM public."Users" WHERE email=$1`
err = db.QueryRow(chekr,usr.Email).Scan()
if err != sql.ErrNoRows {
data,err := json.Marshal("There is already a user with this email")
if err != nil { w.Write(data) }
}
// code that should run if email isn't found
}
但是,我发现它永远不会起作用,并且总是传递if块。
解决方法
如上述评论所述,我忘记了* / 1。 QueryRow可以正常工作,我只是在某处出现了另一个错误。正如其他人所说的那样,还有其他错误,这仅是一种情况的检验。