-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
58 lines (44 loc) · 1.38 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
// Go Program to get page information from URLs.
package main
import (
"os"
"time"
"github.com/jpnewman/urlinfo/profiling"
"github.com/jpnewman/urlinfo/report"
)
// Report Report
var Report = report.New()
func main() {
LogInit("urlinfo.log")
args := parseArgs()
defer func() {
errDoneProf := profiling.ProfileMem(args.memProfile, "Done")
if errDoneProf != nil {
Logger.Fatal(errDoneProf)
}
}()
defer profiling.TimeElapsed("Program Done")(Report.PrintMessage, LogPrintInfo)
Logger.Infof("Program Started: %s", os.Args)
errsProfiling := profiling.StartCPUProfiling(args.cpuProfile)
for _, errProfiling := range errsProfiling {
if errProfiling != nil {
Logger.Fatal(errProfiling)
}
}
defer profiling.StopCPUProfiling(args.cpuProfile)
Report.SetFormatter(*args.reportFormat)
Report.SetOutputFile(args.reportFile)
Report.PrintHeader("URLInfo")
urls, errs := readURLFile(*args.urlFile)
printFileDetails(urls, errs)
pArgs := processURLsArgs{
httpTimeoutMilliseconds: time.Duration(time.Duration(*args.httpTimeout) * time.Millisecond),
numberOfWorkers: *args.numberOfWorkers,
getHeadOny: *args.getHeadOny,
dontFollowRedirects: *args.dontFollowRedirects,
dryRun: *args.dryRun,
}
client := createHTTPClient(pArgs.httpTimeoutMilliseconds, pArgs.dontFollowRedirects)
processURLs(urls, &pArgs, client)
LogFileClose()
}