Skip to content

Instantly share code, notes, and snippets.

@dumebi
Created June 14, 2020 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dumebi/80bdd9785e2a2c2c99435a59a697249f to your computer and use it in GitHub Desktop.
Save dumebi/80bdd9785e2a2c2c99435a59a697249f to your computer and use it in GitHub Desktop.
type User struct {
mogo.DocumentModel `bson:",inline" coll:"users"`
Username string `json:"username" binding:"required"`
Email string `idx:"{email},unique" json:"email" binding:"required"`
Password string `json:"password" binding:"required"`
FirstName string `json:"firstname"`
LastName string `json:"lastname"`
// CreatedAt *time.Time
// UpdatedAt *time.Time
Verified *time.Time `json:"_verified"`
}
func init() {
mogo.ModelRegistry.Register(User{})
}
// Activate service removes one user
func (userservice Userservice) Update(user *entity.User, data map[string]interface{}) (*entity.User, error) {
conn := db.GetConnection()
defer conn.Session.Close()
doc := mogo.NewDoc(user).(*(entity.User))
for k, v := range data {
fmt.Printf("%s is also %s", k, v)
// (doc)[k] = v
}
err := mogo.Save(doc)
if vErr, ok := err.(*mogo.ValidationError); ok {
return nil, vErr
}
err = mogo.Save(doc)
return doc, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment