示例#1
0
func (t *Tickets) List(c context.Context, w http.ResponseWriter, r *http.Request) error {
	var res = make([]api.Ticket, 0)

	_ = t.app.DB.View(func(tx *bolt.Tx) error {
		b := tx.Bucket(t.bucket)
		c := b.Cursor()
		for k, v := c.First(); k != nil; k, v = c.Next() {
			var t api.Ticket
			json.Unmarshal(v, &t)
			res = append(res, t)
		}
		return nil
	})
	return json.NewEncoder(w).Encode(res)
}