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