Example #1
0
func seedData(db *db.DB) {
	var textContent = `
 This is a **sample text in markdown**!

 It contains:

  * lists
  * bold text
  * [links](http://example.com)

 Also, it features blocks of code

     func main() {
 	   fmt.Println("Here be fire dragons!")
     }
 	`
	var items = []*model.Item{
		&model.Item{Code: "url", Type: model.URLItemType, Content: "https://ariejan.net", CreatedAt: time.Now()},
		&model.Item{Code: "txt", Type: model.TextItemType, Content: textContent, CreatedAt: time.Now()},
	}

	for _, item := range items {
		db.SaveItem(item)
	}
}
Example #2
0
func itemsCreateHandler(db *db.DB) gin.HandlerFunc {
	return func(c *gin.Context) {
		var item *model.Item
		if c.BindJSON(&item) == nil {
			if storedItem, err := db.SaveItem(item); err == nil {
				c.JSON(http.StatusCreated, gin.H{
					"item": storedItem,
				})
			} else {
				c.String(http.StatusInternalServerError, "Could not create item.")
			}
		}
	}
}