mirror of
https://gitlab.com/pnx-tools/dns-updater.git
synced 2026-06-16 05:54:56 +02:00
28 lines
569 B
Go
28 lines
569 B
Go
package dns
|
|
|
|
type DomainRecordCache struct {
|
|
domains map[string]RecordList
|
|
fetcher Fetcher
|
|
}
|
|
|
|
type Fetcher func(domain string) (RecordList, error)
|
|
|
|
func NewDomainRecordCache(fetcher Fetcher) *DomainRecordCache {
|
|
return &DomainRecordCache{
|
|
fetcher: fetcher,
|
|
domains: make(map[string]RecordList),
|
|
}
|
|
}
|
|
|
|
func (c *DomainRecordCache) Get(domain string) (RecordList, error) {
|
|
records, ok := c.domains[domain]
|
|
if !ok {
|
|
var err error
|
|
records, err = c.fetcher(domain)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
c.domains[domain] = records
|
|
}
|
|
return records, nil
|
|
}
|