-
Notifications
You must be signed in to change notification settings - Fork 1
/
templates.go
46 lines (44 loc) · 995 Bytes
/
templates.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright © Paul Tötterman <paul.totterman@gmail.com>. All rights reserved.
package main
const adminPage = `
<html>
<head>
<title>URL Shortener</title>
<script type="text/javascript">
function deleteLink(name) {
var xhr = window.XMLHttpRequest ? new XMLHttpRequest() :
new ActiveXObject('Microsoft.HTTP');
xhr.open('DELETE', '/' + name);
xhr.onreadystatechange = function() {
if (xhr.readyState > 3 && xhr.status == 200) {
window.location.href = '/_admin';
}
};
xhr.send();
}
</script>
</head>
<body>
<p>
<form action="{{.path}}" method="post">
<input name="name" id="name" placeholder="name">
<input name="url" id="url" placeholder="https://...">
<input name="user" id="user" placeholder="username" value="{{.user}}">
<input type="submit" value="Add">
</form>
</p>
<p>
<ul>
{{range .urls}}
<li>
<a href="/{{.name}}">{{.name}}</a>
<a href="{{.url}}">{{.url}}</a>
{{.hits}}
<a href="#" onclick="deleteLink('{{.name}}');">Delete</a>
</li>
{{end}}
</ul>
</p>
</body>
</html>
`