-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
59 lines (48 loc) · 1.14 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"bufio"
"fmt"
"log"
"net/http"
"os"
"strings"
"time"
"github.com/joho/godotenv"
"github.com/vkhangstack/check-domain-status/mail"
)
func main() {
godotenv.Load()
data := make([]string, 0)
// open file
f, err := os.Open("domains.txt")
if err != nil {
log.Fatal(err)
}
// remember to close the file at the end of the program
defer f.Close()
// read the file line by line using scanner
scanner := bufio.NewScanner(f)
for scanner.Scan() {
// do something with a line
fmt.Println("***********************************************")
domain := scanner.Text()
fmt.Printf("domain: %s\n", domain)
// isDomain := utils.IsDomain(domain)
// fmt.Println(isDomain)
// if !isDomain {
// fmt.Fprintf(os.Stdout, "not isDomain: %s\n", []any{isDomain}...)
// }
http.DefaultClient.Timeout = 2 * time.Second
res, err := http.Get(domain)
if err != nil || res.StatusCode != 200 {
data = append(data, domain)
}
}
fmt.Printf("List domain failed: %s\r\n", data)
if len(data) != 0 {
errEmail := mail.SendNotificationMail(strings.Join(data, "\n"))
if errEmail != nil {
fmt.Println(err.Error())
}
}
}