summaryrefslogtreecommitdiffstats
path: root/internal/formatter/dns.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/formatter/dns.go')
-rw-r--r--internal/formatter/dns.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/formatter/dns.go b/internal/formatter/dns.go
index 6abd5b0..8e66039 100644
--- a/internal/formatter/dns.go
+++ b/internal/formatter/dns.go
@@ -1,6 +1,7 @@
package formatter
import (
+ "bytes"
"encoding/json"
"fmt"
"strings"
@@ -55,3 +56,37 @@ func FormatDNSResults(result *models.DomainResult, asJSON bool) (string, error)
return sb.String(), nil
}
+
+func FormatDNSSite(resp *models.DNSResponse, asJSON bool) (string, error) {
+ if asJSON {
+ data, err := json.MarshalIndent(resp, "", " ")
+ if err != nil {
+ return "", fmt.Errorf("failed to marshal JSON: %w", err)
+ }
+ return string(data), nil
+ }
+
+ var buf bytes.Buffer
+
+ if resp.Error != "" {
+ fmt.Fprintf(&buf, "%s\n", Red(fmt.Sprintf("Error: %s", resp.Error)))
+ return buf.String(), nil
+ }
+
+ if resp.Message != "" {
+ fmt.Fprintf(&buf, "%s\n", Bold(Cyan(resp.Message)))
+ }
+
+ if resp.Response != "" {
+ fmt.Fprintf(&buf, "%s\n", resp.Response)
+ }
+
+ if resp.Data != nil && len(resp.Data) > 0 {
+ dataJSON, err := json.MarshalIndent(resp.Data, "", " ")
+ if err == nil {
+ fmt.Fprintf(&buf, "\n%s\n", string(dataJSON))
+ }
+ }
+
+ return buf.String(), nil
+}