Browse Source

feat(mod): introduce the /etcd/mod namespace

introduce the `/etcd/mod` namespace and add the dashboard into it.
Brandon Philips 12 years ago
parent
commit
1d6a6d20d1
4 changed files with 27 additions and 8 deletions
  1. 3 1
      etcd_handlers.go
  2. 1 1
      mod/README.md
  3. 8 6
      mod/dashboard/dashboard.go
  4. 15 0
      mod/mod.go

+ 3 - 1
etcd_handlers.go

@@ -24,6 +24,7 @@ import (
 
 
 	etcdErr "github.com/coreos/etcd/error"
 	etcdErr "github.com/coreos/etcd/error"
 	"github.com/coreos/etcd/store"
 	"github.com/coreos/etcd/store"
+	"github.com/coreos/etcd/mod"
 	"github.com/coreos/go-raft"
 	"github.com/coreos/go-raft"
 )
 )
 
 
@@ -41,7 +42,8 @@ func NewEtcdMuxer() *http.ServeMux {
 	etcdMux.Handle("/"+version+"/stats/", errorHandler(StatsHttpHandler))
 	etcdMux.Handle("/"+version+"/stats/", errorHandler(StatsHttpHandler))
 	etcdMux.Handle("/version", errorHandler(VersionHttpHandler))
 	etcdMux.Handle("/version", errorHandler(VersionHttpHandler))
 	etcdMux.HandleFunc("/test/", TestHttpHandler)
 	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
 	return etcdMux
 }
 }
 
 

+ 1 - 1
mod/README.md

@@ -1,7 +1,7 @@
 ## Etcd modules
 ## Etcd modules
 
 
 etcd modules (mods) are higher order pieces of functionality that only
 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.
 of the etcd service.
 
 
 The basic idea is that etcd can ship things like dashboards, master
 The basic idea is that etcd can ship things like dashboards, master

+ 8 - 6
etcd_modules.go → mod/dashboard/dashboard.go

@@ -1,15 +1,16 @@
-package main
+package dashboard
 
 
 import (
 import (
 	"bytes"
 	"bytes"
+	"fmt"
 	"net/http"
 	"net/http"
 	"os"
 	"os"
 	"time"
 	"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
 	path := req.URL.Path
 	if len(path) == 0 {
 	if len(path) == 0 {
 		path = "index.html"
 		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
 // 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
 // dashboard assets or if ETCD_DASHBOARD_DIR is set uses that as the source of
 // assets.
 // 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
 	// Serve the dashboard from a filesystem if the magic env variable is enabled
 	dashDir := os.Getenv("ETCD_DASHBOARD_DIR")
 	dashDir := os.Getenv("ETCD_DASHBOARD_DIR")
@@ -38,5 +40,5 @@ func DashboardHttpHandler(prefix string) (handler http.Handler) {
 		handler = http.FileServer(http.Dir(dashDir))
 		handler = http.FileServer(http.Dir(dashDir))
 	}
 	}
 
 
-	return http.StripPrefix(prefix, handler)
+	return handler
 }
 }

+ 15 - 0
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
+}