Skip to content

Commit 1143e1b

Browse files
committed
web ui: refactor HTML response
- use go:embed to move template string into a file - apply light styling to the output
1 parent fc4b70d commit 1143e1b

File tree

2 files changed

+73
-29
lines changed

2 files changed

+73
-29
lines changed

exporter/exporter.go

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package exporter
22

33
import (
4+
_ "embed"
45
"encoding/json"
56
"fmt"
67
"html/template"
@@ -27,9 +28,15 @@ func (c *Client) Start(listenAddress, version string) error {
2728
log.Printf("fetching AP groups failed: %v", err)
2829
}
2930

31+
portals, err := c.fetchGuestPortals(r.Context())
32+
if err != nil {
33+
log.Printf("fetching guest portals failed: %v", err)
34+
}
35+
3036
err = tmpl.Execute(w, &indexVariables{
3137
Instance: c.instance.String(),
3238
Groups: apGroups,
39+
Portals: portals,
3340
Version: version,
3441
})
3542
if err != nil {
@@ -155,35 +162,11 @@ func (c *Client) portalDebugHandler(w http.ResponseWriter, r *http.Request, para
155162
type indexVariables struct {
156163
Instance string
157164
Groups []string
165+
Portals []string
158166
Version string
159167
}
160168

161-
var tmpl = template.Must(template.New("index").Option("missingkey=error").Parse(`<!doctype html>
162-
<html>
163-
<head>
164-
<meta charset="UTF-8">
165-
<title>Cambium cnMaestro Cloud Exporter (Version {{.Version}})</title>
166-
</head>
167-
<body>
168-
<h1>Cambium cnMaestro Cloud Exporter</h1>
169-
<p>Version: {{.Version}}</p>
170-
<p><a href="{{ .Instance }}" target="_blank">Open controller in new tab.</a></p>
171-
172-
<h2>Endpoints</h2>
173-
<ul>
174-
<li>
175-
<a href="/apgroups">List of WiFi AP Group names</a> (JSON)
176-
</li>
177-
<li>
178-
<strong>Metrics</strong>
179-
<ul>{{ range .Groups }}
180-
<li>
181-
<a href="/apgroups/{{ . }}/metrics">{{ . }}</a> &bull;
182-
<a href="/apgroups/{{ . }}/debug">debug data</a> (JSON)
183-
</li>
184-
{{ end }}</ul>
185-
</li>
186-
</ul>
187-
</body>
188-
</html>
189-
`))
169+
//go:embed exporter.html
170+
var tmplData string
171+
172+
var tmpl = template.Must(template.New("index").Option("missingkey=error").Parse(tmplData))

exporter/exporter.html

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Cambium cnMaestro Cloud Exporter (Version {{ .Version }})</title>
6+
7+
<style>
8+
html, body, table { font: 14px/1.3 sans-serif }
9+
table { border-collapse: collapse; border: solid #333; border-width: 1px 0 }
10+
thead th { border-bottom: 2px solid #333 }
11+
tbody td { border-top: 1px solid #333 }
12+
td, th { text-align: left; vertical-align: top; padding: 3px 6px }
13+
a { color: #00f }
14+
a:visited { color: #00f }
15+
a:hover { text-decoration: none }
16+
</style>
17+
</head>
18+
<body>
19+
<h1>Cambium cnMaestro Cloud Exporter</h1>
20+
<p>Version: {{ .Version }}</p>
21+
<p><a href="{{ .Instance }}" target="_blank">Open controller in new tab.</a></p>
22+
23+
<h2>Endpoints</h2>
24+
25+
<h3>WiFi AP Group targets</h3>
26+
27+
<table>
28+
<thead>
29+
<tr>
30+
<th>Target name</th>
31+
<th>Debug data</th>
32+
</tr>
33+
</thead>
34+
35+
<tbody>
36+
{{ range .Groups }}<tr>
37+
<td><a href="/apgroups/{{ . }}/metrics"><code>apgroups/{{ . }}</code></a></td>
38+
<td><a href="/apgroups/{{ . }}/debug">JSON</a></td>
39+
</tr>{{ end }}
40+
</tbody>
41+
</table>
42+
43+
<h3>Guest Access Portals</h3>
44+
45+
<table>
46+
<thead>
47+
<tr>
48+
<th>Target name</th>
49+
<th>Debug data</th>
50+
</tr>
51+
</thead>
52+
53+
<tbody>
54+
{{ range .Portals }}<tr>
55+
<td><a href="/portals/{{ . }}/metrics"><code>portals/{{ . }}</code></a></td>
56+
<td><a href="/portals/{{ . }}/debug">JSON</a></td>
57+
</tr>{{ end }}
58+
</tbody>
59+
</table>
60+
</body>
61+
</html>

0 commit comments

Comments
 (0)