go/svc/leasifier: fixes, add statusz table
diff --git a/go/svc/leasifier/statusz.go b/go/svc/leasifier/statusz.go
new file mode 100644
index 0000000..7f34a37
--- /dev/null
+++ b/go/svc/leasifier/statusz.go
@@ -0,0 +1,73 @@
+package main
+
+import (
+	"context"
+
+	mirko "code.hackerspace.pl/hscloud/go/mirko"
+	"code.hackerspace.pl/hscloud/go/statusz"
+)
+
+const statuszFragment = `
+    <style type="text/css">
+		.table td,th {
+			background-color: #eee;
+			padding: 0.2em 0.4em 0.2em 0.4em;
+		}
+		.table th {
+			background-color: #c0c0c0;
+		}
+		.table {
+			background-color: #fff;
+			border-spacing: 0.2em;
+		}
+	</style>
+	<div>
+	<b>Current leases:</b> {{ .Leases | len }}<br />
+	<table class="table">
+		<tr>
+      		<th>IP Address</th>
+      		<th>MAC Address</th>
+			<th>Start</th>
+			<th>End</th>
+		</tr>
+		{{range .Leases }}
+		<tr>
+			<td>{{ .IP }}</td>
+			<td>{{ .MAC }}</td>
+			<td>{{ .Start }}</td>
+			<td>{{ .End }}</td>
+		</tr>
+		{{end}}
+	</table>
+	</div>
+`
+
+type szLeases struct {
+	IP    string
+	MAC   string
+	Start string
+	End   string
+}
+
+func (s *service) setupStatusz(m *mirko.Mirko) {
+	statusz.AddStatusPart("Leases", statuszFragment, func(ctx context.Context) interface{} {
+		c := make(chan []lease)
+		s.leaseC <- c
+		leases := <-c
+
+		ls := make([]szLeases, len(leases))
+
+		for i, l := range leases {
+			ls[i].IP = l.ip.String()
+			ls[i].MAC = l.hardware.String()
+			ls[i].Start = l.from.String()
+			ls[i].End = l.to.String()
+		}
+
+		return struct {
+			Leases []szLeases
+		}{
+			Leases: ls,
+		}
+	})
+}