From 72919ec31b727b77c625c29c2a2dc23e471836f5 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 3 Sep 2015 21:16:10 +0800 Subject: [PATCH] use tango instead mux --- .gitignore | 2 ++ server.go => web.go | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 8 deletions(-) rename server.go => web.go (82%) diff --git a/.gitignore b/.gitignore index daf913b..b9d99d8 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,5 @@ _testmain.go *.exe *.test *.prof + +gosuv \ No newline at end of file diff --git a/server.go b/web.go similarity index 82% rename from server.go rename to web.go index e59b4df..c24de7c 100644 --- a/server.go +++ b/web.go @@ -8,8 +8,8 @@ import ( "os/exec" "time" - "github.com/gorilla/mux" - "github.com/qiniu/log" + "github.com/lunny/tango" + "github.com/lunny/log" ) type JSONResponse struct { @@ -92,10 +92,16 @@ func shutdownHandler(w http.ResponseWriter, r *http.Request) { func ServeAddr(host string, port int) error { InitServer() - r := mux.NewRouter() - r.HandleFunc("/api/version", versionHandler) - r.Methods("POST").Path("/api/shutdown").HandlerFunc(shutdownHandler) - r.Methods("POST").Path("/api/programs").HandlerFunc(addHandler) - r.Methods("GET").Path("/api/programs").HandlerFunc(statusHandler) - return http.ListenAndServe(fmt.Sprintf("%s:%d", host, port), r) + + t := tango.New() + + t.Group("/api", func(g *tango.Group) { + g.Get("/version", versionHandler) + g.Post("/shutdown", shutdownHandler) + g.Post("/programs", addHandler) + g.Get("/programs", statusHandler) + }) + + t.Run(fmt.Sprintf("%s:%d", host, port)) + return nil }