Skip to content

Commit

Permalink
go serve
Browse files Browse the repository at this point in the history
  • Loading branch information
kingster committed Apr 13, 2022
1 parent 6732482 commit fb405a6
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions cmd/dkvsrv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"github.com/flipkart-incubator/dkv/meta"
"io"
"io/ioutil"
"log"
Expand All @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
49 changes: 49 additions & 0 deletions internal/www.go
Original file line number Diff line number Diff line change
@@ -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)
}
14 changes: 7 additions & 7 deletions internal/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
<link href="//cdnjs.cloudflare.com/ajax/libs/c3/0.4.15/c3.css" rel="stylesheet" type="text/css">

<!-- monitoring -->
<link rel="stylesheet" href="/css/main.css">
<script type="text/javascript" src="/js/main.js"></script>
<script type="text/javascript" src="/js/config.js"></script>
<script type="text/javascript" src="/js/controllers.js"></script>
<script type="text/javascript" src="/js/services.js"></script>
<script type="text/javascript" src="/js/directives.js"></script>
<script type="text/javascript" src="/js/lib.js"></script>
<link rel="stylesheet" href="/admin/css/main.css">
<script type="text/javascript" src="/admin/js/main.js"></script>
<script type="text/javascript" src="/admin/js/config.js"></script>
<script type="text/javascript" src="/admin/js/controllers.js"></script>
<script type="text/javascript" src="/admin/js/services.js"></script>
<script type="text/javascript" src="/admin/js/directives.js"></script>
<script type="text/javascript" src="/admin/js/lib.js"></script>

<!-- css-->
<style>
Expand Down
4 changes: 2 additions & 2 deletions internal/www/js/config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
CONFIG={
"router": {
"Home":{
"path":"/",
"path":"/admin/",
"controller":"HomeCtrl",
"templateUrl": "home.html",
"templateUrl": "/admin/home.html",
},
},
};
6 changes: 3 additions & 3 deletions internal/www/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@
function($location, $scope, $rootScope ,$timeout, $sce, DKVService) {
/* discover master nodes from here*/
$scope.masters = {
"m1":"http://127.0.0.1:7081",
"m2":"http://127.0.0.1:7082",
"m3":"http://127.0.0.1:7083",
"m1":"http://127.0.0.1:8081",
"m2":"http://127.0.0.1:8082",
"m3":"http://127.0.0.1:8083",
}

$scope.througputParser = througputParser
Expand Down
2 changes: 1 addition & 1 deletion internal/www/js/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
.directive("headerNav", function() {
return {
restrict: "E",
templateUrl: "header-nav.html",
templateUrl: "/admin/header-nav.html",
controller: function($scope, $rootScope, $location, $sce) {
$scope.config = CONFIG;
}
Expand Down
2 changes: 1 addition & 1 deletion internal/www/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
});
}
$routeProvider.otherwise({
redirectTo: "/"
redirectTo: "/admin/"
});
$locationProvider.html5Mode(true);
})
Expand Down
3 changes: 0 additions & 3 deletions internal/www/run.sh

This file was deleted.

4 changes: 3 additions & 1 deletion version/version.go → meta/meta.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package version
package meta

var (
// Version holds the latest version of the DKV binary
Version = "latest"

Release = "Development"
)

0 comments on commit fb405a6

Please sign in to comment.