title: "sql: no rows in result set"
body: <p>I am handling user auth data posted to my Go backend through an HTML form. I am building on <a href="https://github.com/Massad/gin-boilerplate/blob/master/README.md" rel="nofollow noreferrer">some boilerplate</a> to learn Go better.</p>
  
  <p>My problem is what the following <code>func</code> returns:</p>
  
  <pre><code>func (ctrl UserController) Signin(c *gin.Context) {
  
    var signinForm forms.SigninForm
    user, err := userModel.Signin(signinForm)
  
    if err := c.ShouldBindWith(&amp;signinForm, binding.Form); err != nil {
        c.JSON(406, gin.H{"message": "Invalid signin form", "form": signinForm})
        c.Abort()
        return
    }
  
      if err == nil {
          session := sessions.Default(c)
          session.Set("user_id", user.ID)
          session.Set("user_email", user.Email)
          session.Set("user_name", user.Name)
          session.Save()
  
          c.JSON(200, gin.H{"message": "User signed in", "user": user})
      } else {
          c.JSON(406, gin.H{"message": "Invalid signin details", "error": err.Error()})
      }
  
  }
  </code></pre>
  
  <p>The first <code>if</code> statement validates the input, and that works fine (error if the email isn't in proper email format, no error if it is). However, if input is properly validated, the <code>else</code> clause of the second statement is triggered, and the following JSON is returned:</p>
  
  <pre><code>{
  error: "sql: no rows in result set",
  message: "Invalid signin details"
  }
  </code></pre>
  
  <p>It is probably useful to also post the relevant code in my <code>User</code> model:</p>
  
  <pre><code>//User ...
  type User struct {
      ID        int    `db:"id, primarykey, autoincrement" json:"id"`
      Email     string `db:"email" json:"email"`
      Password  string `db:"password" json:"-"`
      Name      string `db:"name" json:"name"`
      UpdatedAt int64  `db:"updated_at" json:"updated_at"`
      CreatedAt int64  `db:"created_at" json:"created_at"`
  }
  
  //UserModel ...
  type UserModel struct{}
  
  //Signin ...
  func (m UserModel) Signin(form forms.SigninForm) (user User, err error) {
  
      err = db.GetDB().SelectOne(&amp;user, "SELECT id, email, password, name, updated_at, created_at FROM public.user WHERE email=LOWER($1) LIMIT 1", form.Email)
  
      if err != nil {
          return user, err
      }
  
      bytePassword := []byte(form.Password)
      byteHashedPassword := []byte(user.Password)
  
      err = bcrypt.CompareHashAndPassword(byteHashedPassword, bytePassword)
  
      if err != nil {
          return user, errors.New("Invalid password")
      }
  
      return user, nil
  }
  </code></pre>
  
  <p>How do I resolve the <code>sql: no rows in result set</code> error?</p>