Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9da49f2d86 | |||
| 356322bc94 |
+12
-5
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"net/netip"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"darvaza.org/core"
|
||||
@@ -47,19 +48,25 @@ func SortRecords(s []libdns.Record) []libdns.Record {
|
||||
}
|
||||
|
||||
func lessRecord(a, b libdns.Record) bool {
|
||||
aName := strings.ToLower(a.Name)
|
||||
bName := strings.ToLower(b.Name)
|
||||
|
||||
switch {
|
||||
case a.Name < b.Name:
|
||||
case aName < bName:
|
||||
return true
|
||||
case a.Name > b.Name:
|
||||
case aName > bName:
|
||||
return false
|
||||
}
|
||||
|
||||
aType := strings.ToUpper(a.Type)
|
||||
bType := strings.ToUpper(b.Type)
|
||||
|
||||
switch {
|
||||
case a.Type < b.Type:
|
||||
case aType < bType:
|
||||
return true
|
||||
case a.Type > b.Type:
|
||||
case aType > bType:
|
||||
return false
|
||||
case a.Type == "A", a.Type == "AAAA":
|
||||
case aType == "A", aType == "AAAA":
|
||||
// IP Addresses
|
||||
var aa, ba netip.Addr
|
||||
|
||||
|
||||
+6
-3
@@ -14,14 +14,17 @@ import (
|
||||
|
||||
// Show shows current DNS entries
|
||||
func (mgr *Manager) Show(ctx context.Context, names ...string) error {
|
||||
var buf bytes.Buffer
|
||||
|
||||
recs, err := mgr.GetRecords(ctx, names...)
|
||||
if err != nil {
|
||||
return core.Wrap(err, "GetRecords")
|
||||
}
|
||||
|
||||
SortRecords(recs)
|
||||
return writeRecords(recs, os.Stdout)
|
||||
}
|
||||
|
||||
func writeRecords(recs []libdns.Record, w io.Writer) error {
|
||||
var buf bytes.Buffer
|
||||
|
||||
for _, rr := range recs {
|
||||
_ = fmtRecord(&buf, rr)
|
||||
@@ -29,7 +32,7 @@ func (mgr *Manager) Show(ctx context.Context, names ...string) error {
|
||||
}
|
||||
_, _ = fmt.Fprintf(&buf, "; %v records\n", len(recs))
|
||||
|
||||
_, err = buf.WriteTo(os.Stdout)
|
||||
_, err := buf.WriteTo(w)
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user