Skip to content

Commit

Permalink
add new example
Browse files Browse the repository at this point in the history
  • Loading branch information
Grantley Cullar authored and Grantley Cullar committed Oct 20, 2022
1 parent 54a6019 commit b70655d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 38 deletions.
8 changes: 8 additions & 0 deletions _example/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"dmarcrecord": "v=DMARC1; p=reject; rua=mailto:[email protected]",
"domain": "google.com",
"hasdmarc": true,
"hasmx": true,
"hasspf": false,
"sprecord": ""
}
7 changes: 7 additions & 0 deletions _example/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/gospacedev/mail-checker"

func main() {
mail.CheckDomainMX("google.com", "config", "json", ".")
}
10 changes: 0 additions & 10 deletions example/main.go

This file was deleted.

7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
23 changes: 2 additions & 21 deletions mail.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package mail
package main

import (
"log"
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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()
}

0 comments on commit b70655d

Please sign in to comment.