What is wrong with this golang code? Ask the boss to take a look.

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:

clipboard.png

clipboard.png

What is the reason for

?

Jan.25,2022

what about the implementation of your Create function?


look at you, r originally got username and phone, not

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eab298-202a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eab298-202a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?