what is wrong with this golang code? Ask the boss to take a look:
this is a function registered by the user. The code is as follows:
func Signup(c *gin.Context) {
var r CreateRequest
if err := c.Bind(&r); err != nil {
SendResponse(c, errno.ErrBind, nil)
return
}
u := model.User{
Username: r.Username,
Phone: r.Phone,
Password: r.Password,
}
//
if err := u.Validate(); err != nil {
SendResponse(c, errno.ErrValidation, nil)
fmt.Println(err) //
return
}
//
if err := u.Encrypt(); err != nil {
SendResponse(c, errno.ErrEncrypt, nil)
return
}
//
if err := u.Create(); err != nil {
SendResponse(c, errno.ErrDatabase, nil)
fmt.Println(err) //
return
}
// Sign the json web token.
t, err := token.Sign(c, token.Context{ID: u.Id, Username: u.Username}, "")
if err != nil {
SendResponse(c, errno.ErrToken, nil)
return
}
SendResponse(c, nil, model.Token{Token: t})
}
question:
successfully inserted a piece of data into the database, but username and phone are empty, as shown in the screenshot below:
What is the reason for
?