// NewController initializes a new instance of our controller. // It provides handler methods for our router. func NewController(bk *buckets.Bucket) *Controller { // map of days to integers daynum := map[string]int{ "mon": 1, // monday is the first day of the week "tue": 2, "wed": 3, "thu": 4, "fri": 5, "sat": 6, "sun": 7, } // map of scanners for iterating over keys subsets of keys scan := map[string]buckets.Scanner{ "mon": bk.NewPrefixScanner([]byte("1")), "tue": bk.NewPrefixScanner([]byte("2")), "wed": bk.NewPrefixScanner([]byte("3")), "thu": bk.NewPrefixScanner([]byte("4")), "fri": bk.NewPrefixScanner([]byte("5")), "sat": bk.NewPrefixScanner([]byte("6")), "sun": bk.NewPrefixScanner([]byte("7")), // weekdays are mon to fri: 1 <= key < 6. "weekday": bk.NewRangeScanner([]byte("1"), []byte("6")), // weekends are sat to sun: 6 <= key < 8. "weekend": bk.NewRangeScanner([]byte("6"), []byte("8")), } return &Controller{bk, daynum, scan} }
// NewController initializes a new instance of our controller. // It provides handler methods for our router. func NewController(bk *buckets.Bucket) *Controller { prefix := map[string]*buckets.PrefixScanner{ "/mon": bk.NewPrefixScanner([]byte("/mon")), "/tue": bk.NewPrefixScanner([]byte("/tue")), "/wed": bk.NewPrefixScanner([]byte("/wed")), "/thu": bk.NewPrefixScanner([]byte("/thu")), "/fri": bk.NewPrefixScanner([]byte("/fri")), "/sat": bk.NewPrefixScanner([]byte("/sat")), "/sun": bk.NewPrefixScanner([]byte("/sun")), } return &Controller{bk, prefix} }