diff --git a/_example/config.json b/_example/config.json new file mode 100644 index 0000000..3296ea4 --- /dev/null +++ b/_example/config.json @@ -0,0 +1,8 @@ +{ + "dmarcrecord": "v=DMARC1; p=reject; rua=mailto:mailauth-reports@google.com", + "domain": "google.com", + "hasdmarc": true, + "hasmx": true, + "hasspf": false, + "sprecord": "" +} \ No newline at end of file diff --git a/_example/main.go b/_example/main.go new file mode 100644 index 0000000..90a590f --- /dev/null +++ b/_example/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/gospacedev/mail-checker" + +func main() { + mail.CheckDomainMX("google.com", "config", "json", ".") +} diff --git a/example/main.go b/example/main.go deleted file mode 100644 index b3dfdc0..0000000 --- a/example/main.go +++ /dev/null @@ -1,10 +0,0 @@ -package main - -import ( - - "github.com/gospacedev/mail-checker" -) - -func main() { - mail.CheckDomainMX("google.com", ) -} diff --git a/go.mod b/go.mod index 07de353..bce3ff6 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,8 @@ -module mail-checker +module github.com/gospacedev/mail-checker go 1.19 -require ( - github.com/gospacedev/mail-checker v0.0.0-20221020042155-d3e1bed6c53b - github.com/spf13/viper v1.13.0 -) +require github.com/spf13/viper v1.13.0 require ( github.com/fsnotify/fsnotify v1.5.4 // indirect diff --git a/go.sum b/go.sum index d33516a..2ab776f 100644 --- a/go.sum +++ b/go.sum @@ -116,8 +116,6 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g= -github.com/gospacedev/mail-checker v0.0.0-20221020042155-d3e1bed6c53b h1:xJJt5Xh7u01DYASpU0kz2UwFm+1UVZS2glQnqFToigg= -github.com/gospacedev/mail-checker v0.0.0-20221020042155-d3e1bed6c53b/go.mod h1:uLQhCOJEn5QJPB+xsdL9nw4qvhWQXwr7iCzGJdN2CSs= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= diff --git a/mail.go b/mail.go index 58cbeec..65259a4 100644 --- a/mail.go +++ b/mail.go @@ -1,4 +1,4 @@ -package mail +package main import ( "log" @@ -8,23 +8,6 @@ import ( "github.com/spf13/viper" ) -// `DomMailInfo` is a struct with fields `Domain`, `HasMX`, `HasSPF`, `HasDMARC`, `SPRRecord`, and -// `DMARCRecord`. -// @property {string} Domain - The domain name -// @property {bool} HasMX - Does the domain have an MX record? -// @property {bool} HasSPF - Does the domain have an SPF record? -// @property {bool} HasDMARC - Does the domain have a DMARC record? -// @property {string} SPRRecord - The SPF record for the domain -// @property {string} DMARCRecord - The DMARC record for the domain. -type DomMailInfo struct { - Domain string `json:"Domain"` - HasMX bool `json:"HasMX"` - HasSPF bool `json:"HasSPF"` - HasDMARC bool `json:"HasDMARC"` - SPRRecord string `json:"SPRRecord"` - DMARCRecord string `json:"DMARCRecord"` -} - /* CheckDomainMX takes a domain name as a string, and returns email information containing the domain name, whether the domain has MX records, whether the domain @@ -44,7 +27,7 @@ func CheckDomainMX(domain string, fileName string, fileType string, filePath str err := vp.ReadInConfig() if err != nil { - log.Fatal(err) + log.Printf("Error: %v\n", err) } mxRecords, err := net.LookupMX(domain) @@ -84,13 +67,11 @@ func CheckDomainMX(domain string, fileName string, fileType string, filePath str } } - // parse info in config file vp.Set("domain", domain) vp.Set("HasMX", HasMX) vp.Set("HasSPF", HasSPF) vp.Set("HasDMARC", HasDMARC) vp.Set("SPRecord", SPRRecord) vp.Set("DMARCRecord", DMARCRecord) - vp.WriteConfig() }