-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
92 lines (74 loc) · 1.9 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"context"
"github.com/joho/godotenv"
"log"
"os"
"webcrawler/awsx"
localConfig "webcrawler/config"
"webcrawler/dynamoDBx"
"webcrawler/graphx"
"webcrawler/handler"
"webcrawler/queue"
)
func main() {
// Load .env file
err := godotenv.Load()
ctx := context.Background()
if err != nil {
log.Fatalf("Failed to load .env file with error: %v", err)
}
if err != nil {
log.Fatalf("Cannot load the AWS config: %s", err)
}
cfg, err := awsx.GetConfig(ctx)
if err != nil {
log.Fatalf("Cannot load the AWS config: %s", err)
}
sqsClient := queue.New(
os.Getenv("LINKS_QUEUE"),
cfg,
)
dbClient := dynamoDBx.New(
os.Getenv("DB_TABLE_PAGE"),
os.Getenv("DB_TABLE_WEBSITE"),
cfg,
)
graphConn, err := graphx.Conn(ctx, os.Getenv("NEO4J_USER"), os.Getenv("NEO4J_PASSWORD"), os.Getenv("NEO4J_URL"))
if err != nil {
log.Fatalf("Cannot connect to the graph database: %s", err)
}
graph := graphx.New(graphConn)
config := localConfig.Fetch()
server := handler.New(dbClient, sqsClient, graph, config)
initialLinks := []string{
"https://blog.alexcollie.com/",
"https://alexcollie.com",
"https://reddit.com",
"https://reddit.com/r/golang",
"https://reddit.com/r/technology",
"https://reddit.com/r/python",
"https://reddit.com/r/javascript",
"https://reddit.com/r/rust",
"https://reddit.com/r/java",
"https://bbc.co.uk",
"https://bbc.co.uk/news",
"https://bbc.co.uk/sport",
"https://bbc.co.uk/weather",
"https://bbc.co.uk/food",
"https://cnn.com",
"https://cnn.com/world",
"https://cnn.com/us",
"https://news.ycombinator.com",
"https://news.ycombinator.com/newest",
"https://hackernews.com",
"https://techcrunch.com",
"https://techcrunch.com/startups",
"https://waitbutwhy.com/",
"https://arstechnica.com/",
"https://www.wired.com/",
"https://www.theverge.com/",
}
server.Queue.AddFromString(ctx, initialLinks)
server.Scan(ctx)
}