diff --git a/etcd_handlers.go b/etcd_handlers.go index ca62e4a62..cc0c79a6d 100644 --- a/etcd_handlers.go +++ b/etcd_handlers.go @@ -24,6 +24,7 @@ import ( etcdErr "github.com/coreos/etcd/error" "github.com/coreos/etcd/store" + "github.com/coreos/etcd/mod" "github.com/coreos/go-raft" ) @@ -41,7 +42,8 @@ func NewEtcdMuxer() *http.ServeMux { etcdMux.Handle("/"+version+"/stats/", errorHandler(StatsHttpHandler)) etcdMux.Handle("/version", errorHandler(VersionHttpHandler)) etcdMux.HandleFunc("/test/", TestHttpHandler) - etcdMux.Handle("/mod/dashboard/", DashboardHttpHandler("/mod/dashboard/")) + // TODO: Use a mux in 0.2 that can handle this + etcdMux.Handle("/etcd/mod/dashboard/", *mod.ServeMux) return etcdMux } diff --git a/mod/README.md b/mod/README.md index 5fd9c1782..2dde92975 100644 --- a/mod/README.md +++ b/mod/README.md @@ -1,7 +1,7 @@ ## Etcd modules etcd modules (mods) are higher order pieces of functionality that only -speak to the client etcd API and are presented in the `/mod` HTTP path +speak to the client etcd API and are presented in the `/etcd/mod` HTTP path of the etcd service. The basic idea is that etcd can ship things like dashboards, master diff --git a/etcd_modules.go b/mod/dashboard/dashboard.go similarity index 70% rename from etcd_modules.go rename to mod/dashboard/dashboard.go index a0397bd76..ff9ed43c8 100644 --- a/etcd_modules.go +++ b/mod/dashboard/dashboard.go @@ -1,15 +1,16 @@ -package main +package dashboard import ( "bytes" + "fmt" "net/http" "os" "time" - "github.com/coreos/etcd/dashboard/resources" + "github.com/coreos/etcd/mod/dashboard/resources" ) -func DashboardMemoryFileServer(w http.ResponseWriter, req *http.Request) { +func memoryFileServer(w http.ResponseWriter, req *http.Request) { path := req.URL.Path if len(path) == 0 { path = "index.html" @@ -29,8 +30,9 @@ func DashboardMemoryFileServer(w http.ResponseWriter, req *http.Request) { // DashboardHttpHandler either uses the compiled in virtual filesystem for the // dashboard assets or if ETCD_DASHBOARD_DIR is set uses that as the source of // assets. -func DashboardHttpHandler(prefix string) (handler http.Handler) { - handler = http.HandlerFunc(DashboardMemoryFileServer) +func HttpHandler() (handler http.Handler) { + fmt.Println("hello world") + handler = http.HandlerFunc(memoryFileServer) // Serve the dashboard from a filesystem if the magic env variable is enabled dashDir := os.Getenv("ETCD_DASHBOARD_DIR") @@ -38,5 +40,5 @@ func DashboardHttpHandler(prefix string) (handler http.Handler) { handler = http.FileServer(http.Dir(dashDir)) } - return http.StripPrefix(prefix, handler) + return handler } diff --git a/mod/mod.go b/mod/mod.go new file mode 100644 index 000000000..f764d6c2f --- /dev/null +++ b/mod/mod.go @@ -0,0 +1,15 @@ +// mod is the entry point to all of the etcd modules. +package mod + +import ( + "net/http" + "github.com/coreos/etcd/mod/dashboard" +) + +var ServeMux *http.Handler + +func init() { + // TODO: Use a Gorilla mux to handle this in 0.2 and remove the strip + handler := http.StripPrefix("/etcd/mod/dashboard/", dashboard.HttpHandler()) + ServeMux = &handler +}