Exemple #1
0
func notHelper(idxs []uint64) []uint64 {
	// create a temp array for returned idx's
	aTempReturn := make([]uint64, 0)

	// now, take the inverse of the idx's matched
	// first, find how many records we have
	numRecords := data.CountRecords()

	// create two vals for looping
	i := uint64(0)
	j := uint64(0)
	for ; i < numRecords && j < uint64(len(idxs)); i++ {
		switch i {
		case idxs[j]:
			// this is an idx that we found; don't add it to our return array!
			j++
		default:
			// it's not in our list of idx's; let's add it to our return!
			aTempReturn = append(aTempReturn, i)
		}
	}

	// now, add the remaining idx's
	// the length of aTemp will never be greater than the length of the entire db,
	// so we only have to do this once and not on aTemp
	for ; i < numRecords; i++ {
		aTempReturn = append(aTempReturn, i)
	}

	return aTempReturn
}
Exemple #2
0
func countKeys(res http.ResponseWriter, req *http.Request) {
	if req.Method == "GET" {

		type count struct {
			Count uint64
		}
		c1 := count{data.CountRecords()}

		jsonData, err := json.Marshal(c1)
		if err != nil {
			log.Print(err)
		}

		// write the headers
		res.Header().Set("Content-Type", "application/json")

		// send back the response
		res.Write(jsonData)
		res.WriteHeader(http.StatusOK)
	} else {
		// do POST / PUT / DELETE stuff

		// write the headers
		res.Header().Set("Content-Type", "text/plain")

		// send back the response
		res.Write([]byte("Pretty Damn Quick!\n"))
		res.WriteHeader(http.StatusOK)
	}
}