53 lines
933 B
Go
53 lines
933 B
Go
package hosts
|
|
|
|
import (
|
|
"github.com/miekg/dns"
|
|
"time"
|
|
)
|
|
|
|
var (
|
|
zeroDuration = time.Duration(0)
|
|
)
|
|
|
|
type Host struct {
|
|
Type uint16 `json:"type"`
|
|
TTL time.Duration `json:"ttl"`
|
|
Values []string `json:"values"`
|
|
}
|
|
|
|
func (h *Host) TypeString() string {
|
|
return dns.TypeToString[h.Type]
|
|
}
|
|
|
|
type Hosts interface {
|
|
Get(queryType uint16, domain string) (*Host, error)
|
|
}
|
|
|
|
type ProviderList struct {
|
|
providers []Provider
|
|
}
|
|
|
|
type Provider interface {
|
|
Get(queryType uint16, domain string) (*Host, error)
|
|
Set(domain string, host *Host) error
|
|
}
|
|
|
|
func NewHosts(providers []Provider) Hosts {
|
|
return &ProviderList{providers}
|
|
}
|
|
|
|
// Get Matches values to providers, loping each in order
|
|
func (h *ProviderList) Get(queryType uint16, domain string) (*Host, error) {
|
|
var host *Host
|
|
var err error
|
|
|
|
for _, provider := range h.providers {
|
|
host, err = provider.Get(queryType, domain)
|
|
|
|
if host != nil {
|
|
break
|
|
}
|
|
}
|
|
|
|
return host, err
|
|
} |