Chapter 4 – Building API Authentication
- In order to create a user or sign them up, we need to define a HTTP handler with
SignUpHandle
r as follows:func (handler *AuthHandler) SignUpHandler(c *gin.Context) { var user models.User if err := c.ShouldBindJSON(&user); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } cur := handler.collection.FindOne(handler.ctx, bson.M{ "username": user.Username, }) if curTalent.Err() == mongo.ErrNoDocuments...