dashboard: list record types in the README's order (closes #226)
check / check (push) Canceled after 0s

Each row of the Hostnames table listed a nameserver's record types in
the order Go happens to walk the record map, which changed from row to
row and on every page load, so two nameservers with the same records
looked different. formatRecords now sorts the types by their place in
the README's list (A, AAAA, CNAME, MX, TXT, SRV, CAA, NS); any other
type comes after them in alphabetical order. Values within a type were
already sorted by the resolver.

Model: opus-5-5
This commit was merged in pull request #243.
This commit is contained in:
2026-10-02 09:55:07 +02:00
parent 250f3dd687
commit 1218df9467
3 changed files with 68 additions and 3 deletions
+27 -3
View File
@@ -1,11 +1,14 @@
package handlers
import (
"cmp"
"embed"
"fmt"
"html/template"
"maps"
"math"
"net/http"
"slices"
"strings"
"time"
@@ -122,16 +125,37 @@ func joinStrings(items []string, sep string) string {
}
// formatRecords formats a map of record type → values into a
// compact display string.
// compact display string. Record types are listed in the order the
// README lists them, any other type after them in alphabetical order,
// so rows of nameservers with the same records read the same.
func formatRecords(records map[string][]string) string {
if len(records) == 0 {
return "-"
}
order := []string{"A", "AAAA", "CNAME", "MX", "TXT", "SRV", "CAA", "NS"}
position := func(rtype string) int {
i := slices.Index(order, rtype)
if i < 0 {
return len(order)
}
return i
}
rtypes := slices.Collect(maps.Keys(records))
slices.SortFunc(rtypes, func(a, b string) int {
return cmp.Or(
cmp.Compare(position(a), position(b)),
strings.Compare(a, b),
)
})
var parts []string
for rtype, values := range records {
for _, v := range values {
for _, rtype := range rtypes {
for _, v := range records[rtype] {
parts = append(parts, rtype+": "+v)
}
}