package pancheri import ( "fmt" "github.com/miekg/dns" "time" ) type Zone struct { Root string ReducedHash string Zonefile string ARecords []RecordA AAAARecords []RecordAAAA CNAMERecords []RecordCNAME TXTRecords []RecordTXT } func (z *Zone) RenderZone() string { outString := "" outString += fmt.Sprintf(";; Rendered zonefile for %s (rsha %s) at %s\n", z.Zonefile, z.ReducedHash, time.Now().Format(time.RFC3339)) outString += ";; Generated by pancheri-render. Note: this will NOT work out of the box!\n" outString += ";; At the very least, you'll need to change the SOA and NS values.\n" outString += "\n" outString += ";; SOA & NS records\n" outString += ";; TODO\n" outString += "\n" outString += ";; A Records\n" for _, record := range z.ARecords { 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 outString += r.String() + "\n" } outString += ";; AAAA Records\n" for _, record := range z.AAAARecords { 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 outString += r.String() + "\n" } outString += ";; CNAME Records\n" for _, record := range z.CNAMERecords { 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 outString += r.String() + "\n" } outString += ";; TXT Records\n" for _, record := range z.TXTRecords { 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 outString += r.String() + "\n" } return outString }