-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
47 lines (41 loc) · 918 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
package main
import (
"flag"
"fmt"
"github.com/wesleyvicthor/myhttp/pkg"
"os"
)
func main() {
const defaultParallel int = 10
var limitRequests int
flag.Usage = help
flag.IntVar(&limitRequests, "parallel", defaultParallel, "Limit the number of parallel requests")
flag.Parse()
if len(flag.Args()) == 0 {
flag.Usage()
os.Exit(1)
}
myHTTP := myhttp.New(flag.Args())
done := make(chan struct{})
result, fail := myHTTP.ProcessParallel(limitRequests, done)
defer close(result)
for {
select {
case resp := <-result:
fmt.Printf("%s %x\n", resp.Url, resp.MD5)
case msg := <-fail:
fmt.Println(msg)
case <-done:
return
}
}
}
func help() {
fmt.Println(`myhttp:
Display the MD5 hash of the response body for the given url.
Usage:
myhttp [option] [urls ...]
Options:
-parallel Limit the number of parallel requests
-help Display this help message.`)
}