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

introduce the `/etcd/mod` namespace and add the dashboard into it.
release-0.4
Brandon Philips 2013-10-09 13:54:44 -07:00
parent 32f562a013
commit 1d6a6d20d1
4 changed files with 27 additions and 8 deletions

View File

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

View File

@ -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

View File

@ -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) { func HttpHandler() (handler http.Handler) {
handler = http.HandlerFunc(DashboardMemoryFileServer) 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
mod/mod.go Normal file
View File

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