-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
33 lines (25 loc) · 856 Bytes
/
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
package main
import (
"crawler/internal/crawl"
"flag"
"github.com/rs/zerolog/log"
"time"
)
func main() {
url := flag.String("url", "", "Base URL of the domain to be crawled")
out := flag.String("out", "", "Path to the output file")
logLevel := flag.String("logging", "info", "Sets the log level to debug")
reqTimeoutSecs := flag.Int("timeout", 5, "Single HTTP request timeout in seconds")
flag.Parse()
setupLogging(logLevel)
validateFlags(url, out)
file := setupOutFile(out)
defer file.Close()
linksFetcher := setupFetcher(url, reqTimeoutSecs)
start := time.Now()
log.Info().Msgf("Crawling %v, this might take minutes...", *url)
siteMap := <-crawl.GenerateSiteMap(*url, linksFetcher)
log.Info().Msgf("Generating site map...")
siteMap.PrintToFile(file)
log.Info().Msgf("Finished site map of %v in %s", *url, time.Since(start))
}