1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Refactor in preparation to unexport RecordConfig.{Name,NameFQDN,Target} (#337)

* Preparing for the unexport of Name/NameFQDN/Target
* Cleanups
This commit is contained in:
Tom Limoncelli
2018-03-19 17:18:58 -04:00
committed by GitHub
parent cd58d26545
commit a7eba97ada
37 changed files with 298 additions and 270 deletions

View File

@@ -178,7 +178,7 @@ func parseLeaf(results models.Records, k string, v interface{}, origin string) (
case "port": // SRV
newRc.SrvPort = uint16(v4.(int))
case "value": // MX
newRc.Target = v4.(string)
newRc.SetTarget(v4.(string))
}
}
//fmt.Printf("parseLeaf: append %v\n", newRc)

View File

@@ -56,7 +56,9 @@ func TestYamlWrite(t *testing.T) {
m.AddFunc("json", minjson.Minify)
t.Run(f.Name(), func(t *testing.T) {
content, err := ioutil.ReadFile(filepath.Join(testDir, f.Name()))
fname := filepath.Join(testDir, f.Name())
fmt.Printf("Filename: %v\n", fname)
content, err := ioutil.ReadFile(fname)
if err != nil {
t.Fatal(err)
}

View File

@@ -48,14 +48,14 @@ func (z *genYamlData) Less(i, j int) bool {
case "NS", "TXT", "TLSA":
// pass through.
case "A":
ta2, tb2 := net.ParseIP(a.Target), net.ParseIP(b.Target)
ta2, tb2 := net.ParseIP(a.GetTargetField()), net.ParseIP(b.GetTargetField())
ipa, ipb := ta2.To4(), tb2.To4()
if ipa == nil || ipb == nil {
log.Fatalf("should not happen: IPs are not 4 bytes: %#v %#v", ta2, tb2)
}
return bytes.Compare(ipa, ipb) == -1
case "AAAA":
ta2, tb2 := net.ParseIP(a.Target), net.ParseIP(b.Target)
ta2, tb2 := net.ParseIP(a.GetTargetField()), net.ParseIP(b.GetTargetField())
ipa, ipb := ta2.To16(), tb2.To16()
return bytes.Compare(ipa, ipb) == -1
case "MX":
@@ -75,7 +75,7 @@ func (z *genYamlData) Less(i, j int) bool {
return pa < pb
}
case "PTR":
pa, pb := a.Target, b.Target
pa, pb := a.GetTargetField(), b.GetTargetField()
if pa != pb {
return pa < pb
}

View File

@@ -28,8 +28,9 @@ func WriteYaml(w io.Writer, records models.Records, origin string) error {
recsCopy = append(recsCopy, r)
}
for _, r := range recsCopy {
if r.Name == "@" {
r.Name = ""
if r.GetLabel() == "@" {
//r.Name = ""
r.UnsafeSetLabelNull()
}
}
@@ -156,7 +157,7 @@ func sameType(records models.Records) bool {
func oneLabel(records models.Records) yaml.MapItem {
item := yaml.MapItem{
// a yaml.MapItem is a YAML map that retains the key order.
Key: records[0].Name,
Key: records[0].GetLabel(),
}
// Special case labels with a single record:
if len(records) == 1 {