Exemple #1
0
// PostUser insert a new user
func PostUser(c echo.Context) error {
	db := midd.GetMgo(c)
	user := User{ID: bson.NewObjectId(), Fname: "Mister", Lname: "Valaire"}

	_, err := db.C(userC).UpsertId(user.ID, user)
	if err != nil {
		return err
	}
	return c.JSON(200, user)
}
Exemple #2
0
// GetUser returns a document found by the id.
func GetUser(c echo.Context) error {
	db := midd.GetMgo(c)
	user := User{}
	userID := bson.ObjectIdHex(c.Param("id"))

	err := db.C(userC).FindId(userID).One(&user)
	if err != nil {
		return err
	}
	return c.JSON(200, user)
}