diff --git a/pkg/model/model.go b/pkg/model/model.go index 2a886fa..eb1a77f 100644 --- a/pkg/model/model.go +++ b/pkg/model/model.go @@ -3,11 +3,11 @@ package model type Results struct { IP string `json:"ip"` Hostname string `json:"hostname"` - TXT string `json:"TXT,omitempty"` + TXT string `json:"TXT` } type UniqResults struct { IP string `json:"ip"` Hostname string `json:"hostname"` - TXT string `json:"TXT,omitempty"` + TXT string `json:"TXT"` } diff --git a/pkg/resolver/resolver.go b/pkg/resolver/resolver.go index a451b22..96614df 100644 --- a/pkg/resolver/resolver.go +++ b/pkg/resolver/resolver.go @@ -1,12 +1,14 @@ package resolver import ( + "encoding/json" "errors" "fmt" "log" "strings" "git.linuxrocker.com/mattburchett/go_tab-magic/pkg/config" + "git.linuxrocker.com/mattburchett/go_tab-magic/pkg/model" "github.com/miekg/dns" ) @@ -66,24 +68,27 @@ func PerformZoneTransfer(config config.Config) { default: continue } - // data = append(data, fmt.Sprintf("%v %v %v\n", strings.TrimRight(hostname, "."), ip, txt)) - - for _, i := range data { - checkval := fmt.Sprintf("%v %v ", strings.TrimRight(hostname, "."), ip) - fmt.Printf("CheckVal: %v", checkval) - actualval := fmt.Sprintf("%v %v %v", strings.TrimRight(hostname, "."), ip, txt) - fmt.Printf("ActualVal: %v", actualval) - if i == checkval { - if i != actualval { - i = actualval - } - - } else { - data = append(data, fmt.Sprintf("%v %v %v\n", strings.TrimRight(hostname, "."), ip, txt)) - } - } + data = append(data, fmt.Sprintf("%v %v %v\n", strings.TrimRight(hostname, "."), ip, txt)) } } } fmt.Println(data) + resultsToJSON(data) +} + +func resultsToJSON(data []string) { + for _, i := range data { + splitStrings := strings.Split(i, " ") + hostname := splitStrings[1] + ip := splitStrings[2] + txt := splitStrings[3] + dns := &model.Results{IP: ip, Hostname: hostname, TXT: txt} + b, err := json.Marshal(dns) + if err != nil { + fmt.Println(err) + } + fmt.Println(string(b)) + + } + }