-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
64 lines (49 loc) · 1011 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
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
package main
import (
"fetch-go/fetch"
"fetch-go/utils"
"sync"
"time"
flag "github.com/spf13/pflag"
)
var printMetadata bool
var validURLs []string
func init() {
flag.BoolVar(&printMetadata, "metadata", false, "Display Metadata or not")
}
func main() {
flag.Parse()
args := flag.Args()
validURLs = utils.ParseURI(args)
// fmt.Println("metadata?", printMetadata)
// fmt.Println(validURLs)
// extract links from content
// fetch and save date from above links
// rewrite links to suitable for local file system
// save the rewited content to index.html file
var wg sync.WaitGroup
for _, url := range validURLs {
url := url
instance := fetch.Fetch{
WG: &sync.WaitGroup{},
Input: &fetch.FetchInput{
BaseURL: url,
Time: time.Now(),
},
}
if printMetadata {
instance.MPrint()
} else {
wg.Add(1)
go func() {
defer wg.Done()
instance.FetchALL()
instance.SavePage()
instance.Wait()
}()
}
}
if !printMetadata {
wg.Wait()
}
}