Beispiel #1
0
func bitcaskPutHandle(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	key := vars["key"]
	if len(key) <= 0 {
		w.Write([]byte("key invalid"))
		return
	}
	value, err := ioutil.ReadAll(r.Body)
	if err != nil {
		logger.Error(err)
		w.WriteHeader(500)
		return
	}

	bc.Put([]byte(key), value)
	w.Write([]byte("Success"))
}
Beispiel #2
0
func bitcaskDelHandle(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	key := vars["key"]
	if len(key) <= 0 {
		w.Write([]byte("key invalid"))
		return
	}

	err := bc.Del([]byte(key))
	if err != nil && err != bitcask.ErrNotFound {
		logger.Error(err)
		w.WriteHeader(500)
		return
	}
	if err == bitcask.ErrNotFound {
		w.WriteHeader(404)
		w.Write([]byte(bitcask.ErrNotFound.Error()))
		return
	}

	w.Write([]byte("Success"))
}