-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (44 loc) · 1.02 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
package main
import (
"bufio"
"flag"
"fmt"
"os"
"os/signal"
"time"
)
func readFile(path string) []string {
file, err := os.Open(path)
if err != nil {
fmt.Printf("Unable to open file %s: %s\n", path, err.Error())
os.Exit(1)
}
defer file.Close()
var lines []string
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if len(scanner.Text()) > 0 {
lines = append(lines, scanner.Text())
}
}
return lines
}
func main() {
sleep := flag.Uint("sleep", 250, "number of microseconds to sleep between keys")
conc := flag.Uint("threads", 2, "amount of concurrent goroutines that should run at the same time")
file := flag.String("file", "", "input file")
flag.Parse()
if len(*file) == 0 {
fmt.Println("You must specify a file to open")
os.Exit(1)
}
targets = readFile(*file)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
<-c
fmt.Println("Total run time:", time.Since(now), i, "keys")
os.Exit(0)
}()
Start(*sleep, *conc)
}