diff --git a/Makefile b/Makefile index eb7237b4..4709a890 100644 --- a/Makefile +++ b/Makefile @@ -24,10 +24,10 @@ ifeq ($(VERSION),) endif BUILD_TAGS = 'osusergo netgo static_build' -LDFLAGS = -ldflags '-linkmode external -extldflags "-static" -X "github.com/flipkart-incubator/dkv/version.Version=$(VERSION)"' +LDFLAGS = -ldflags '-linkmode external -extldflags "-static" -X "github.com/flipkart-incubator/dkv/meta.Version=$(VERSION)" -X "github.com/flipkart-incubator/dkv/meta.Release=Production"' ifeq ($(GOOS),darwin) - LDFLAGS = -ldflags '-X "github.com/flipkart-incubator/dkv/version.Version=$(VERSION)"' + LDFLAGS = -ldflags '-X "github.com/flipkart-incubator/dkv/meta.Version=$(VERSION)"' BUILD_TAGS = 'osusergo netgo' endif diff --git a/cmd/dkvsrv/main.go b/cmd/dkvsrv/main.go index e563f8f3..1a055515 100644 --- a/cmd/dkvsrv/main.go +++ b/cmd/dkvsrv/main.go @@ -3,6 +3,7 @@ package main import ( "encoding/json" "fmt" + "github.com/flipkart-incubator/dkv/meta" "io" "io/ioutil" "log" @@ -20,6 +21,7 @@ import ( "github.com/prometheus/client_golang/prometheus/promhttp" "gopkg.in/ini.v1" + "github.com/flipkart-incubator/dkv/internal" "github.com/flipkart-incubator/dkv/internal/discovery" "github.com/flipkart-incubator/dkv/internal/master" "github.com/flipkart-incubator/dkv/internal/opts" @@ -520,6 +522,11 @@ func setupHttpServer() { router.HandleFunc("/debug/pprof/trace", pprof.Trace) } + //Admin UI + liveMode := meta.Release == "Development" + fileSystem := internal.GetWWWFileSystem(liveMode) + router.PathPrefix("/admin/").Handler(http.StripPrefix("/admin/", http.FileServer(fileSystem))) + http.Handle("/", router) http.ListenAndServe(config.HttpListenAddr, nil) } diff --git a/go.mod b/go.mod index f835daa3..4a09c6a4 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/flipkart-incubator/dkv -go 1.15 +go 1.16 require ( github.com/Jille/grpc-multi-resolver v1.0.0 diff --git a/internal/www.go b/internal/www.go new file mode 100644 index 00000000..56cc7ec6 --- /dev/null +++ b/internal/www.go @@ -0,0 +1,49 @@ +package internal + +import ( + "embed" + "fmt" + "io/fs" + "log" + "net/http" + "os" + "path/filepath" + "runtime" +) + +//go:embed www +var embededFiles embed.FS + +func getFileDir() string { + _, file, _, ok := runtime.Caller(0) + if !ok { + file = "./" + } else { + file = filepath.Dir(file) + } + + dir := fmt.Sprintf("%s/www", file) + return dir +} + +func GetWWWFileSystem(develMode bool) http.FileSystem { + + if develMode { + dir := getFileDir() + log.Print("using live mode with Dir: ", dir) + return http.FS(os.DirFS(dir)) + } + + log.Println("using embed mode") + fSys, err := fs.Sub(embededFiles, "www") + if err != nil { + panic(err) + } + + //fs.WalkDir(fsys, ".", func(p string, d fs.DirEntry, err error) error { + // fmt.Println(p) + // return nil + //}) + + return http.FS(fSys) +} diff --git a/internal/www/index.html b/internal/www/index.html index 728567f5..66e61354 100644 --- a/internal/www/index.html +++ b/internal/www/index.html @@ -39,13 +39,13 @@ - - - - - - - + + + + + + +