Пример #1
0
// Retrieve the list of assets GET /api/assets
func retrieveAssets(w http.ResponseWriter, r *http.Request) {
	var assets []Asset
	var row Asset

	query := gocb.NewN1qlQuery("SELECT name, uri, note FROM `assets` ORDER BY name ASC")
	rows, err := bucket.ExecuteN1qlQuery(query, nil)

	if err != nil {
		http.Error(w, "N1QL query error: "+err.Error(), 500)
		return
	}

	for rows.Next(&row) {
		assets = append(assets, row)
	}

	if err := rows.Close(); err != nil {
		http.Error(w, "N1QL query error: "+err.Error(), 500)
		return
	}

	b, _ := json.Marshal(assets)
	w.Write(b)
}
Пример #2
0
func docQuery(uri string) *gocb.N1qlQuery {
	return gocb.NewN1qlQuery("SELECT uri, name, note FROM `assets` WHERE assets.uri=" + sanitize(uri))
}