86 lines
1.3 KiB
Go
86 lines
1.3 KiB
Go
package pancheri
|
|
|
|
import (
|
|
"github.com/miekg/dns"
|
|
"net"
|
|
)
|
|
|
|
const (
|
|
RuleTypeA = "A"
|
|
RuleTypeAAAA = "AAAA"
|
|
RuleTypeCNAME = "CNAME"
|
|
RuleTypeTXT = "TXT"
|
|
)
|
|
|
|
type RecordA struct {
|
|
In string
|
|
Ip net.IP
|
|
TTL uint
|
|
}
|
|
|
|
func (record *RecordA) Render() *dns.A {
|
|
r := new(dns.A)
|
|
r.Hdr = dns.RR_Header{
|
|
Name: record.In,
|
|
Rrtype: dns.TypeA,
|
|
Class: dns.ClassINET,
|
|
Ttl: uint32(record.TTL),
|
|
}
|
|
r.A = record.Ip
|
|
return r
|
|
}
|
|
|
|
type RecordAAAA struct {
|
|
In string
|
|
Ip net.IP
|
|
TTL uint
|
|
}
|
|
|
|
func (record *RecordAAAA) Render() *dns.AAAA {
|
|
r := new(dns.AAAA)
|
|
r.Hdr = dns.RR_Header{
|
|
Name: record.In,
|
|
Rrtype: dns.TypeAAAA,
|
|
Class: dns.ClassINET,
|
|
Ttl: uint32(record.TTL),
|
|
}
|
|
r.AAAA = record.Ip
|
|
return r
|
|
}
|
|
|
|
type RecordCNAME struct {
|
|
In string
|
|
Target string
|
|
TTL uint
|
|
}
|
|
|
|
func (record *RecordCNAME) Render() *dns.CNAME {
|
|
r := new(dns.CNAME)
|
|
r.Hdr = dns.RR_Header{
|
|
Name: record.In,
|
|
Rrtype: dns.TypeCNAME,
|
|
Class: dns.ClassINET,
|
|
Ttl: uint32(record.TTL),
|
|
}
|
|
r.Target = record.Target
|
|
return r
|
|
}
|
|
|
|
type RecordTXT struct {
|
|
In string
|
|
Content []string
|
|
TTL uint
|
|
}
|
|
|
|
func (record *RecordTXT) Render() *dns.TXT {
|
|
r := new(dns.TXT)
|
|
r.Hdr = dns.RR_Header{
|
|
Name: record.In,
|
|
Rrtype: dns.TypeTXT,
|
|
Class: dns.ClassINET,
|
|
Ttl: uint32(record.TTL),
|
|
}
|
|
r.Txt = record.Content
|
|
return r
|
|
}
|