예제 #1
0
func beerSearchHandler(w http.ResponseWriter, r *http.Request) {
	value := r.URL.Query().Get("value")

	vq := gocb.NewViewQuery("beer", "by_name").Limit(entriesPerPage).Stale(gocb.Before)
	vq.Range(value, value+"\u0FFFF", false)

	rows := bucket.ExecuteViewQuery(vq)
	var row beerByNameRow
	var beers []Beer
	for rows.Next(&row) {
		beer := Beer{}

		if _, err := bucket.Get(row.Id, &beer); err != nil {
			fmt.Printf("Get Error: %v\n", err)
			continue
		}

		beer.Id = row.Id
		beers = append(beers, beer)
	}
	if err := rows.Close(); err != nil {
		fmt.Fprintf(w, "Error: %s\n", err)
		return
	}

	bytes, err := json.Marshal(beers)
	if err != nil {
		fmt.Fprintf(w, "Error: %s\n", err)
		return
	}

	w.Write(bytes)
}
예제 #2
0
func beerIndexHandler(w http.ResponseWriter, r *http.Request) {
	vq := gocb.NewViewQuery("beer", "by_name").Limit(entriesPerPage).Stale(gocb.Before)
	rows := bucket.ExecuteViewQuery(vq)
	var row beerByNameRow
	var beers []Beer
	for rows.Next(&row) {
		beer := Beer{}

		if _, err := bucket.Get(row.Id, &beer); err != nil {
			fmt.Printf("Get Error: %v\n", err)
			continue
		}

		beer.Id = row.Id
		beers = append(beers, beer)
	}
	if err := rows.Close(); err != nil {
		fmt.Fprintf(w, "Error: %s\n", err)
		return
	}

	data := tdBeerIndex{
		Results: beers,
	}
	executeTemplate(w, "beer/index.html", data)
}
예제 #3
0
func GetAll() *[]paymentcard.PaymentCard {

	vq := gocb.NewViewQuery("getallfull", "getallfull")
	rows := bucket.ExecuteViewQuery(vq)

	var cards []paymentcard.PaymentCard

	row := viewRow{}
	for rows.Next(&row) {
		cards = append(cards, row.Value)
	}
	if err := rows.Close(); err != nil {
		fmt.Printf("View Query Error: %s", err) // todo: Return an error here.
	}

	return &cards
}
예제 #4
0
func brewIndexHandler(w http.ResponseWriter, r *http.Request) {
	vq := gocb.NewViewQuery("brewery", "by_name").Limit(entriesPerPage)
	rows := bucket.ExecuteViewQuery(vq)
	var row breweryByNameRow
	var breweries []Brewery
	for rows.Next(&row) {
		breweries = append(breweries, Brewery{
			Id:   row.Id,
			Name: row.Key,
		})
	}

	data := tdBrewIndex{
		Results: breweries,
	}
	executeTemplate(w, "brewery/index.html", data)
}
예제 #5
0
func brewSearchHandler(w http.ResponseWriter, r *http.Request) {
	value := r.URL.Query().Get("value")

	vq := gocb.NewViewQuery("brewery", "by_name").Limit(entriesPerPage)
	vq.Range(value, value+"\u0FFFF", false)

	rows := bucket.ExecuteViewQuery(vq)
	var row breweryByNameRow
	var breweries []Brewery
	for rows.Next(&row) {
		breweries = append(breweries, Brewery{
			Id:   row.Id,
			Name: row.Key,
		})
	}

	bytes, err := json.Marshal(breweries)
	if err != nil {
		fmt.Fprintf(w, "Error: %s\n", err)
		return
	}

	w.Write(bytes)
}