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
0c676ac93a
3 changed files with 24 additions and 7 deletions
  1. 1 1
      mod/README.md
  2. 8 6
      mod/dashboard/dashboard.go
  3. 15 0
      mod/mod.go

+ 1 - 1
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

+ 8 - 6
etcd_modules.go → 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
 }

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