use doozer's file2gostring to provide html temp as go string
parent
9146fbf120
commit
494b35596b
|
@ -0,0 +1,26 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
munge() {
|
||||
printf %s "$1" | tr . _ | tr -d -c '[:alnum:]_'
|
||||
}
|
||||
|
||||
quote() {
|
||||
sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/$/\\n/' | tr -d '\n'
|
||||
}
|
||||
|
||||
pkg_path=$1 ; shift
|
||||
file=$1 ; shift
|
||||
|
||||
pkg=`basename $pkg_path`
|
||||
|
||||
printf 'package %s\n' "$pkg"
|
||||
printf '\n'
|
||||
printf '// This file was generated from %s.\n' "$file"
|
||||
printf '\n'
|
||||
printf 'var '
|
||||
munge "`basename $file`"
|
||||
printf ' string = "'
|
||||
quote
|
||||
printf '"\n'
|
|
@ -0,0 +1,5 @@
|
|||
package web
|
||||
|
||||
// This file was generated from index.html.
|
||||
|
||||
var index_html string = "<html>\n<head>\n<title>etcd Web Interface</title>\n<script type=\"text/javascript\" src=\"//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js\"></script>\n<script type=\"text/javascript\">\n $(function() {\n\n var conn;\n var content = $(\"#content\");\n\n function update(response) {\n // if set\n if (response.action == \"SET\") {\n\n if (response.expiration > \"1970\") {\n t = response.key + \"=\" + response.value\n + \" \" + response.expiration\n } else {\n t = response.key + \"=\" + response.value\n }\n\n id = response.key.replace(new RegExp(\"/\", 'g'), \"\\\\/\");\n\n if ($(\"#store_\" + id).length == 0) {\n if (response.expiration > \"1970\") {\n t = response.key + \"=\" + response.value\n + \" \" + response.expiration\n } else {\n t = response.key + \"=\" + response.value\n }\n\n var e = $('<div id=\"store_' + response.key + '\"/>')\n .text(t)\n e.appendTo(content)\n }\n else {\n\n $(\"#store_\" + id)\n .text(t)\n }\n }\n // if delete\n else if (response.action == \"DELETE\") {\n id = response.key.replace(new RegExp(\"/\", 'g'), \"\\\\/\");\n\n $(\"#store_\" + id).remove()\n }\n }\n\n\n if (window[\"WebSocket\"]) {\n conn = new WebSocket(\"ws://{{.Address}}/ws\");\n conn.onclose = function(evt) {\n\n }\n conn.onmessage = function(evt) {\n var response = JSON.parse(evt.data)\n update(response)\n }\n } else {\n appendLog($(\"<div><b>Your browser does not support WebSockets.</b></div>\"))\n }\n });\n</script>\n</head>\n<body>\n <div id=\"leader\">Leader: {{.Leader}}</div>\n <div id=\"content\"></div>\n</body>\n</html>\n"
|
|
@ -0,0 +1,70 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>etcd Web Interface</title>
|
||||
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
|
||||
var conn;
|
||||
var content = $("#content");
|
||||
|
||||
function update(response) {
|
||||
// if set
|
||||
if (response.action == "SET") {
|
||||
|
||||
if (response.expiration > "1970") {
|
||||
t = response.key + "=" + response.value
|
||||
+ " " + response.expiration
|
||||
} else {
|
||||
t = response.key + "=" + response.value
|
||||
}
|
||||
|
||||
id = response.key.replace(new RegExp("/", 'g'), "\\/");
|
||||
|
||||
if ($("#store_" + id).length == 0) {
|
||||
if (response.expiration > "1970") {
|
||||
t = response.key + "=" + response.value
|
||||
+ " " + response.expiration
|
||||
} else {
|
||||
t = response.key + "=" + response.value
|
||||
}
|
||||
|
||||
var e = $('<div id="store_' + response.key + '"/>')
|
||||
.text(t)
|
||||
e.appendTo(content)
|
||||
}
|
||||
else {
|
||||
|
||||
$("#store_" + id)
|
||||
.text(t)
|
||||
}
|
||||
}
|
||||
// if delete
|
||||
else if (response.action == "DELETE") {
|
||||
id = response.key.replace(new RegExp("/", 'g'), "\\/");
|
||||
|
||||
$("#store_" + id).remove()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (window["WebSocket"]) {
|
||||
conn = new WebSocket("ws://{{.Address}}/ws");
|
||||
conn.onclose = function(evt) {
|
||||
|
||||
}
|
||||
conn.onmessage = function(evt) {
|
||||
var response = JSON.parse(evt.data)
|
||||
update(response)
|
||||
}
|
||||
} else {
|
||||
appendLog($("<div><b>Your browser does not support WebSockets.</b></div>"))
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="leader">Leader: {{.Leader}}</div>
|
||||
<div id="content"></div>
|
||||
</body>
|
||||
</html>
|
|
@ -25,7 +25,7 @@ func mainHandler(c http.ResponseWriter, req *http.Request) {
|
|||
}
|
||||
|
||||
func Start(server *raft.Server, port int) {
|
||||
mainTempl = template.Must(template.ParseFiles("web/index.html"))
|
||||
mainTempl = template.Must(template.New("index.html").Parse(index_html))
|
||||
s = server
|
||||
|
||||
go h.run()
|
||||
|
|
Loading…
Reference in New Issue