Browse Source

add delete handler

Xiang Li 12 years ago
parent
commit
4ff786b4a2
2 changed files with 13 additions and 1 deletions
  1. 12 0
      handlers.go
  2. 1 1
      raftd.go

+ 12 - 0
handlers.go

@@ -118,6 +118,18 @@ func GetHttpHandler(w http.ResponseWriter, req *http.Request) {
 
 
 }
 }
 
 
+func DeleteHttpHandler(w http.ResponseWriter, req *http.Request) {
+	vars := mux.Vars(req)
+
+	debug("[recv] GET http://%v/delete/%s", server.Name(), vars["key"])
+
+	command := &DeleteCommand{}
+	command.Key = vars["key"]
+
+	Dispatch(server, command, w)
+
+}
+
 
 
 func Dispatch(server *raft.Server, command Command, w http.ResponseWriter) {
 func Dispatch(server *raft.Server, command Command, w http.ResponseWriter) {
 	var body []byte
 	var body []byte

+ 1 - 1
raftd.go

@@ -130,7 +130,7 @@ func main() {
     // external commands
     // external commands
     r.HandleFunc("/set/{key}", SetHttpHandler).Methods("POST")
     r.HandleFunc("/set/{key}", SetHttpHandler).Methods("POST")
     r.HandleFunc("/get/{key}", GetHttpHandler).Methods("GET")
     r.HandleFunc("/get/{key}", GetHttpHandler).Methods("GET")
-    //r.HandleFunc("/delete/{key}", DeleteHttpHandler).Methods("GET")
+    r.HandleFunc("/delete/{key}", DeleteHttpHandler).Methods("GET")
 
 
     http.Handle("/", r)
     http.Handle("/", r)
 	log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", info.Port), nil))
 	log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", info.Port), nil))