diff --git a/handlers.go b/handlers.go index 23958f5860c..871bacb1c6d 100644 --- a/handlers.go +++ b/handlers.go @@ -5,7 +5,6 @@ import ( "net/http" "encoding/json" "fmt" - "github.com/gorilla/mux" "io/ioutil" "bytes" ) @@ -88,9 +87,9 @@ func SnapshotHttpHandler(w http.ResponseWriter, req *http.Request) { } func SetHttpHandler(w http.ResponseWriter, req *http.Request) { - vars := mux.Vars(req) + key := req.URL.Path[len("/set/"):] - debug("[recv] POST http://%v/set/%s", server.Name(), vars["key"]) + debug("[recv] POST http://%v/set/%s", server.Name(), key) content, err := ioutil.ReadAll(req.Body) if err != nil { @@ -100,7 +99,7 @@ func SetHttpHandler(w http.ResponseWriter, req *http.Request) { } command := &SetCommand{} - command.Key = vars["key"] + command.Key = key command.Value = string(content) Dispatch(server, command, w) @@ -108,24 +107,24 @@ func SetHttpHandler(w http.ResponseWriter, req *http.Request) { } func GetHttpHandler(w http.ResponseWriter, req *http.Request) { - vars := mux.Vars(req) + key := req.URL.Path[len("/get/"):] - debug("[recv] GET http://%v/get/%s", server.Name(), vars["key"]) + debug("[recv] GET http://%v/get/%s", server.Name(), key) command := &GetCommand{} - command.Key = vars["key"] + command.Key = key Dispatch(server, command, w) } func DeleteHttpHandler(w http.ResponseWriter, req *http.Request) { - vars := mux.Vars(req) + key := req.URL.Path[len("/delete/"):] - debug("[recv] GET http://%v/delete/%s", server.Name(), vars["key"]) + debug("[recv] GET http://%v/delete/%s", server.Name(), key) command := &DeleteCommand{} - command.Key = vars["key"] + command.Key = key Dispatch(server, command, w) @@ -133,12 +132,12 @@ func DeleteHttpHandler(w http.ResponseWriter, req *http.Request) { func WatchHttpHandler(w http.ResponseWriter, req *http.Request) { - vars := mux.Vars(req) + key := req.URL.Path[len("/watch/"):] - debug("[recv] GET http://%v/watch/%s", server.Name(), vars["key"]) + debug("[recv] GET http://%v/watch/%s", server.Name(), key) command := &WatchCommand{} - command.Key = vars["key"] + command.Key = key Dispatch(server, command, w) diff --git a/raftd.go b/raftd.go index 08b3b7e13c7..befc774a30a 100644 --- a/raftd.go +++ b/raftd.go @@ -6,7 +6,7 @@ import ( "flag" "fmt" "github.com/benbjohnson/go-raft" - "github.com/gorilla/mux" + //"github.com/gorilla/mux" "log" "io" "io/ioutil" @@ -125,22 +125,25 @@ func main() { //go server.Snapshot() // Create HTTP interface. - r := mux.NewRouter() + //r := mux.NewRouter() // internal commands - r.HandleFunc("/join", JoinHttpHandler).Methods("POST") - r.HandleFunc("/vote", VoteHttpHandler).Methods("POST") - r.HandleFunc("/log", GetLogHttpHandler).Methods("GET") - r.HandleFunc("/log/append", AppendEntriesHttpHandler).Methods("POST") - r.HandleFunc("/snapshot", SnapshotHttpHandler).Methods("POST") + http.HandleFunc("/join", JoinHttpHandler) + http.HandleFunc("/vote", VoteHttpHandler) + http.HandleFunc("/log", GetLogHttpHandler) + http.HandleFunc("/log/append", AppendEntriesHttpHandler) + http.HandleFunc("/snapshot", SnapshotHttpHandler) // external commands - r.HandleFunc("/set/{key}", SetHttpHandler).Methods("POST") - r.HandleFunc("/get/{key}", GetHttpHandler).Methods("GET") - r.HandleFunc("/delete/{key}", DeleteHttpHandler).Methods("GET") - r.HandleFunc("/watch/{key}", WatchHttpHandler).Methods("GET") + http.HandleFunc("/set/", SetHttpHandler) + //r.HandleFunc("/get/{key}", GetHttpHandler).Methods("GET") + http.HandleFunc("/delete/", DeleteHttpHandler) + http.HandleFunc("/watch/", WatchHttpHandler) + + //http.Handle("/", r) + + http.HandleFunc("/get/", GetHttpHandler) - http.Handle("/", r) log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", info.Port), nil)) }