-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.go
91 lines (62 loc) · 1.52 KB
/
update.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
// future updates to main.go feel free to contribute
package main
import (
"errors"
"sync"
"github.com/projectdiscovery/gologger"
)
var errNoScripts = errors.New("no script tags found")
func main() {
// Wrap in goroutine to allow concurrent fetching
scripts, err := fetchScriptsAsync("https://nineatcollegepark2.residentportal.com/auth")
if err != nil {
gologger.Error().Msgf("Could not fetch scripts: %v\n", err)
return
}
if len(scripts) == 0 {
gologger.Error().Msg(errNoScripts)
return
}
endpoints := extractEndpoints(scripts)
// Print endpoints
// etc...
}
// fetcher.go
func fetchScriptsAsync(url string) ([]string, error) {
var scripts []string
var wg sync.WaitGroup
// Spin up 20 concurrent fetchers
for i := 0; i < 20; i++ {
wg.Add(1)
go func() {
defer wg.Done()
script, err := fetchScript(url)
if err != nil {
gologger.Error().Msgf("Fetch error: %v\n", err)
return
}
scripts = append(scripts, script)
}()
}
wg.Wait()
if len(scripts) == 0 {
return nil, errNoScripts
}
return scripts, nil
}
// extractor.go
func extractEndpoints(scripts []string) []string {
// Wrap in goroutine to allow concurrent parsing
var endpoints []string
var wg sync.WaitGroup
for _, script := range scripts {
wg.Add(1)
go func(content string) {
defer wg.Done()
eps := parseScript(content)
endpoints = append(endpoints, eps...)
}(script)
}
wg.Wait()
return endpoints
}