dns: refactor asSyncRecords()
for direct access of the unsorted map Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
+9
-4
@@ -54,7 +54,7 @@ func (mgr *Manager) GetSyncRecords(ctx context.Context) ([]SyncAddrRecord, error
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return mgr.filteredSyncRecords(recs)
|
||||
return mgr.asSyncRecords(recs)
|
||||
}
|
||||
|
||||
// AsSyncAddr converts a A or AAAA [libdns.Record] into a [SyncAddr]
|
||||
@@ -89,9 +89,9 @@ func (mgr *Manager) AsSyncAddr(rr libdns.Record) (SyncAddr, bool, error) {
|
||||
return out, true, nil
|
||||
}
|
||||
|
||||
func (mgr *Manager) filteredSyncRecords(recs []libdns.Record) ([]SyncAddrRecord, error) {
|
||||
func (mgr *Manager) asSyncRecordsMap(recs []libdns.Record) map[string][]SyncAddr {
|
||||
// filter and convert
|
||||
cache := make(map[string][]SyncAddr)
|
||||
out := make(map[string][]SyncAddr)
|
||||
for _, rr := range recs {
|
||||
addr, ok, err := mgr.AsSyncAddr(rr)
|
||||
switch {
|
||||
@@ -106,9 +106,14 @@ func (mgr *Manager) filteredSyncRecords(recs []libdns.Record) ([]SyncAddrRecord,
|
||||
Print()
|
||||
case ok:
|
||||
// store
|
||||
cache[rr.Name] = append(cache[rr.Name], addr)
|
||||
out[rr.Name] = append(out[rr.Name], addr)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (mgr *Manager) asSyncRecords(recs []libdns.Record) ([]SyncAddrRecord, error) {
|
||||
cache := mgr.asSyncRecordsMap(recs)
|
||||
|
||||
// prepare records
|
||||
out := make([]SyncAddrRecord, len(cache))
|
||||
|
||||
Reference in New Issue
Block a user