[REFACTOR] Simplify converting struct to map in admin stats

- Instead of relying on JSON to convert the struct to map, use
`reflect` to do this conversion. Also simplify it a bit by only passing
one variable to the template.
- This avoids issues where the conversion to JSON causes changes in
the value, for example huge numbers are converted to its scientific
notation but are consequently not converted back when being displayed.
- Adds unit tests.
- Resolves an issue where the amount of comments is being displayed in
scientific notation on Codeberg.
This commit is contained in:
Gusted 2024-02-22 22:25:19 +01:00
parent ec1b64637e
commit f68bc0ec6a
No known key found for this signature in database
GPG key ID: FD821B732837125F
3 changed files with 65 additions and 22 deletions

View file

@ -5,10 +5,10 @@
</h4>
<div class="ui attached table segment">
<table class="ui very basic striped table unstackable">
{{range $statsKey := .StatsKeys}}
{{range $statsKey, $statsValue := .Stats}}
<tr>
<td width="200">{{$statsKey}}</td>
<td>{{index $.StatsCounter $statsKey}}</td>
<td>{{$statsValue}}</td>
</tr>
{{end}}
</table>