-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (54 loc) · 1.16 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
package main
import (
"flag"
"fmt"
"sync"
"getGo/funcs"
)
func main() {
flag.Parse()
args := flag.Args()
funcs.DeleteLog()
if *funcs.HelpMessage {
flag.Usage()
return
}
if *funcs.Mirror {
htmlContent, err := funcs.FetchHTML(args[0])
if err != nil {
fmt.Println("Error fetching HTML:", err)
return
}
// Parse HTML and extract resources
resources, err := funcs.ExtractResources(htmlContent, args[0])
if err != nil {
fmt.Println("Error extracting resources:", err)
return
}
// Download and save resources
err = funcs.DownloadResources(resources, args[0])
if err != nil {
fmt.Println("Error downloading resources:", err)
return
}
fmt.Println("Resources downloaded successfully!")
return
}
if *funcs.BgMode {
fmt.Println("Logs will be written to wget-log")
}
// Use a separate wait group for the goroutines
var wg sync.WaitGroup
if *funcs.InputFile != "" {
funcs.MultiReqSend()
} else {
for _, arg := range args {
currentArg := arg
// Increment the new wait group for each goroutine
wg.Add(1)
go funcs.SendSingleRequest(currentArg, &wg)
}
}
// Wait for all downloads to complete
wg.Wait()
}