Exemplo n.º 1
0
func List(c *gin.Context) {

	context := appengine.NewContext(c.Request)
	greetings := models.Greetings{}

	if err := db.NewDatastore(context).Query(greetings.GetAll()).All(&greetings); err != nil {
		statusInternalServerError(c, err)
	} else {
		c.JSON(http.StatusOK, greetings)
	}
}
Exemplo n.º 2
0
func persist(c *gin.Context, content string) {
	context := appengine.NewContext(c.Request)
	greetings := models.Greetings{}

	author := "guest"
	if u := user.Current(context); u != nil {
		author = u.String()
	}
	greeting := greetings.New(author, content)

	if err := db.NewDatastore(context).Create(greeting); err != nil {
		statusInternalServerError(c, err)
		return
	}
}