Skip to content

Commit

Permalink
Rename dht folder to node, add missing DeleteHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
eleksaggr committed Jun 13, 2016
1 parent 2983cbb commit 87a2e8e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 32 deletions.
1 change: 1 addition & 0 deletions follower.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func (follower *Follower) OnDelete(m *Message, w io.Writer) (err error) {
delete(follower.table, m.GetKey())
follower.mutex.Unlock()

log.Printf("Table after Delete: %v\n", follower.table)
return nil
}

Expand Down
42 changes: 10 additions & 32 deletions dht/api.go → node/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,14 @@ func HandleGet(w http.ResponseWriter, r *http.Request) {
}

func HandleDelete(w http.ResponseWriter, r *http.Request) {
// body, err := ioutil.ReadAll(io.LimitReader(r.Body, 1048576))
// if err != nil {
// panic(err)
// }
//
// if err = r.Body.Close(); err != nil {
// panic(err)
// }
//
// var data map[string]interface{}
// if err = json.Unmarshal(body, &data); err != nil {
// w.Header().Set("Content-Type", "application/json; charset=UTF-8")
// w.WriteHeader(422) // unprocessable entity
// if err = json.NewEncoder(w).Encode(err); err != nil {
// panic(err)
// }
// }
//
// key := data["key"].(string)
// value := data["value"].(string)
// message := dht.Message{
// Action: dht.Message_DELETE.Enum(),
// Key: &key,
// Value: &value,
// }
//
// err = server.Role().(*dht.Leader).Delete(key)
// if err != nil {
// w.Write([]byte(err.Error()))
// } else {
// w.Write([]byte("Success\n"))
// }
vars := mux.Vars(r)

key := vars["key"]

err := server.Role().(*dht.Leader).Delete(key)
if err != nil {
w.Write([]byte(err.Error()))
} else {
w.Write([]byte("Success"))
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 87a2e8e

Please sign in to comment.