func (c *Controller) getDayTasks(w http.ResponseWriter, r *http.Request,
	p httprouter.Params) {
	day := p.ByName("day")
	num := c.daynum[day]
	pre := []byte(strconv.Itoa(num))  
	items, err := c.todos.PrefixItems(pre)
	if err != nil {
		http.Error(w, err.Error(), 500)
	}
	taskList := &TaskList{day, []string{}}
	for _, item := range items {
		todo, err := decode(item.Value)
		if err != nil {
			http.Error(w, err.Error(), 500)
		}
		taskList.Tasks = append(taskList.Tasks, todo.Task)
	}
	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(taskList)
}
getDayTasks handles get requests for `/:day`, returning a particular
day's task list.

Note how we utilize the PrefixItems method for the day requested (as
indicated in the route's `day` parameter). This makes it easy to get
items in our todos bucket with a certain prefix, viz. those with the
prefix representing the requested day.
package main
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"net/http/httptest"
	"os"
	"strconv"
	"strings"
	"time"
	"github.com/joyrexus/buckets"
	"github.com/julienschmidt/httprouter"
)
const verbose = false  
func main() {
	bx, err := buckets.Open(tempFilePath())
	if err != nil {
		log.Fatalf("couldn't open db: %v", err)
	}
	defer os.Remove(bx.Path())
	defer bx.Close()
	bucket, err := bx.New([]byte("todos"))
	if err != nil {
		log.Fatalf("couldn't create todos bucket: %v", err)
	}
	control := NewController(bucket)
	router := httprouter.New()
	router.POST("/day/:day", control.post)
	router.GET("/day/:day", control.getDayTasks)
	router.GET("/weekend", control.getWeekendTasks)
	router.GET("/weekdays", control.getWeekdayTasks)
	srv := httptest.NewServer(router)
	defer srv.Close()
	posts := []*Todo{
		{Day: "mon", Task: "milk cows"},
		{Day: "mon", Task: "feed cows"},
		{Day: "mon", Task: "wash cows"},
		{Day: "tue", Task: "wash laundry"},
		{Day: "tue", Task: "fold laundry"},
		{Day: "tue", Task: "iron laundry"},
		{Day: "wed", Task: "flip burgers"},
		{Day: "thu", Task: "join army"},
		{Day: "fri", Task: "kill time"},
		{Day: "sat", Task: "have beer"},
		{Day: "sat", Task: "make merry"},
		{Day: "sun", Task: "take aspirin"},
		{Day: "sun", Task: "pray quietly"},
	}
	client := new(Client)
	for _, todo := range posts {
		url := srv.URL + "/day/" + todo.Day
		if err := client.post(url, todo); err != nil {
			fmt.Printf("client post error: %v", err)
		}
	}
	week := []string{"mon", "tue", "wed", "thu", "fri", "sat", "sun"}
	fmt.Println("daily tasks ...")
	for _, day := range week {
		url := srv.URL + "/day/" + day
		tasks, err := client.get(url)
		if err != nil {
			fmt.Printf("client get error: %v", err)
		}
		fmt.Printf("  %s: %s\n", day, tasks)
	}
	tasks, err := client.get(srv.URL + "/weekdays")
	if err != nil {
		fmt.Printf("client get error: %v", err)
	}
	fmt.Printf("\nweekday tasks: %s\n", tasks)
	tasks, err = client.get(srv.URL + "/weekend")
	if err != nil {
		fmt.Printf("client get error: %v", err)
	}
	fmt.Printf("\nweekend tasks: %s\n", tasks)
}
type Todo struct {
	Task    string     
	Day     string     
	Created time.Time  
}
func (todo *Todo) Encode() (*bytes.Buffer, error) {
	b, err := json.Marshal(todo)
	if err != nil {
		return &bytes.Buffer{}, err
	}
	return bytes.NewBuffer(b), nil
}
type TaskList struct {
	When  string
	Tasks []string
}
func NewController(bk *buckets.Bucket) *Controller {
	daynum := map[string]int{
		"mon": 1,  
		"tue": 2,
		"wed": 3,
		"thu": 4,
		"fri": 5,
		"sat": 6,
		"sun": 7,
	}
	return &Controller{bk, daynum}
}
type Controller struct {
	todos  *buckets.Bucket
	daynum map[string]int
}
func (c *Controller) getWeekendTasks(w http.ResponseWriter, r *http.Request,
	_ httprouter.Params) {
	items, err := c.todos.RangeItems([]byte("6"), []byte("8"))
	if err != nil {
		http.Error(w, err.Error(), 500)
	}
	taskList := &TaskList{"weekend", []string{}}
	for _, item := range items {
		todo, err := decode(item.Value)
		if err != nil {
			http.Error(w, err.Error(), 500)
		}
		taskList.Tasks = append(taskList.Tasks, todo.Task)
	}
	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(taskList)
}
func (c *Controller) getWeekdayTasks(w http.ResponseWriter, r *http.Request,
	_ httprouter.Params) {
	items, err := c.todos.RangeItems([]byte("1"), []byte("6"))
	if err != nil {
		http.Error(w, err.Error(), 500)
	}
	taskList := &TaskList{"weekdays", []string{}}
	for _, item := range items {
		todo, err := decode(item.Value)
		if err != nil {
			http.Error(w, err.Error(), 500)
		}
		taskList.Tasks = append(taskList.Tasks, todo.Task)
	}
	w.Header().Set("Content-Type", "application/json")
	json.NewEncoder(w).Encode(taskList)
}