Example #1
0
// getCoordinates gets all Coordinates
func (c *CoordinatesResource) getCoordinates(r *restful.Request, w *restful.Response) {
	database, _ := db.GetDB()
	col := database.C("hashes")
	result := []map[string]string{}
	col.Find(nil).Distinct("coordinates", &result)
	w.WriteEntity(result)
}
Example #2
0
// getGroups gets all Groups
// @Title getGroups
// @Description returns all known Groups
// @Accept  json
// @Success 200 {object} interface
// @Failure 500 {object} APIError   "Error"
// @Resource /groups
// @Router /service/v3/groups/ [get]
func (g *GroupsResource) getGroups(r *restful.Request, w *restful.Response) {
	database, _ := db.GetDB()
	col := database.C("hashes")
	result := []string{}
	col.Find(nil).Distinct("group", &result)
	w.WriteEntity(result)
}
Example #3
0
// getProduct gets Hashes for a single product
// getProduct gets Hashes for a single product
// @Title getProduct
// @Description returns Hashes for a single product
// @Accept  json
// @Param   name     path       string     true        "Name string"
// @Success 200 {object}  db.Hash
// @Failure 404 {object} APIError   "Error"
// @Resource /product
// @Router /service/v3/product/{name}/ [get]
func (h *Product) getProduct(r *restful.Request, w *restful.Response) {
	name := r.PathParameter("name")
	database, _ := db.GetDB()
	col := database.C("hashes")
	cursor := col.Find(bson.M{"name": name})
	count, _ := cursor.Count()
	if count >= 1 {
		result := []db.Hash{}
		cursor.All(&result)
		w.WriteEntity(result)
	} else {
		w.WriteEntity(APIError{Error: "Object not found."})
	}
}
Example #4
0
// getStatus returns the support status of this API
func (h *HashResource) getHash(r *restful.Request, w *restful.Response) {
	hash := r.PathParameter("hash")
	database, _ := db.GetDB()
	col := database.C("hashes")
	cursor := col.Find(bson.M{"hashes.sha512.combined": hash})
	count, _ := cursor.Count()
	if count == 1 {
		result := db.Hash{}
		cursor.One(&result)
		w.WriteEntity(result)
	} else {
		w.WriteEntity(APIError{Error: "Object not found."})
	}
}