I am having a problem with this library because this function returns false even when the given input is not in the database, when in fact it should return true.
type User struct {
ID uint `gorm:"primary_key"`
Username string `json:",omitempty"`
Password string `json:",omitempty"`
CreatedAt time.Time `json:",omitempty"`
}
b, err := db.Con()
if err != nil {
log.Panic(err)
}
defer db.Close()
// We want an empty struct
// Otherwise it will trigger the unique key constraint
user := []User{}
// Check if the username is taken
// BUX, MUST FIX: This always returns false for some reason
if db.Where(&User{Username: "MyUsername"}).Find(&user).RecordNotFound() == false {
fmt.Println("Username found")
}
Why is it always returning false, even when the string is empty?