func (r *resourceUser) Create(u *models.User) error { if u.Password == "" { return apiErrors.ThrowError(apiErrors.UserPasswordRequired) } u.Password = r.HashPassword(u.Password) u.Id = bson.NewObjectId() u.Role = models.NormalUser if err := collection(userColName).Insert(u); err != nil { if mgo.IsDup(err) { return apiErrors.ThrowError(apiErrors.UserExist) } panic(err) } return nil }