You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
devops/views/index.gohtml

80 lines
2.5 KiB

3 months ago
{{template "base.gohtml"}}
{{define "title"}}Home{{end}}
{{define "head"}}
3 months ago
<script>
3 months ago
window.addEventListener("load", function () {
3 months ago
var output = document.getElementById("output");
var input = document.getElementById("input");
var ws;
3 months ago
var print = function (message) {
3 months ago
var d = document.createElement("div");
d.textContent = message;
output.appendChild(d);
output.scroll(0, output.scrollHeight);
};
3 months ago
document.getElementById("open").onclick = function (evt) {
3 months ago
if (ws) {
return false;
}
ws = new WebSocket("{{.}}");
3 months ago
ws.onopen = function (evt) {
3 months ago
print("OPEN");
}
3 months ago
ws.onclose = function (evt) {
3 months ago
print("CLOSE");
ws = null;
}
3 months ago
ws.onmessage = function (evt) {
3 months ago
print("RESPONSE: " + evt.data);
}
3 months ago
ws.onerror = function (evt) {
3 months ago
print("ERROR: " + evt.data);
}
return false;
};
3 months ago
document.getElementById("send").onclick = function (evt) {
3 months ago
if (!ws) {
return false;
}
print("SEND: " + input.value);
ws.send(input.value);
return false;
};
3 months ago
document.getElementById("close").onclick = function (evt) {
3 months ago
if (!ws) {
return false;
}
ws.close();
return false;
};
});
</script>
3 months ago
{{end}}
{{define "content"}}
<table>
<tr>
<td valign="top" width="50%">
<p>Click "Open" to create a connection to the server,
"Send" to send a message to the server and "Close" to close the connection.
You can change the message and send multiple times.
<p>
<form>
<button id="open">Open</button>
<button id="close">Close</button>
<p><input id="input" type="text" value="Hello world!">
<button id="send">Send</button>
</form>
</td>
<td valign="top" width="50%">
<div id="output" style="max-height: 70vh;overflow-y: scroll;"></div>
</td>
</tr>
</table>
{{end}}