-
Notifications
You must be signed in to change notification settings - Fork 26
/
helpers.go
60 lines (48 loc) · 1.04 KB
/
helpers.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
package helpers
import (
"io/ioutil"
"log"
"os"
"strings"
)
// function to read a file and return urls in a list
func ReadUrlsFromFile(filename string) []string {
// Open a txt file
file, err := os.Open(filename)
if err != nil {
log.Fatal(err)
}
defer file.Close()
// Read the file
data, err := ioutil.ReadAll(file)
if err != nil {
log.Fatal(err)
}
// Convert the data to a string
text := string(data)
// Split the string into a list of urls
urls := strings.Split(text, "\n")
return urls
}
// Splits targets into batches by returning a slice of slices
func SplitSlice(items []string, batchSize int) [][]string {
var batches [][]string
for i := 0; i < len(items); i += batchSize {
end := i + batchSize
if end > len(items) {
end = len(items)
}
batches = append(batches, items[i:end])
}
return batches
}
// Remove empty items for a slice of strings
func RemoveEmpty(items []string) []string {
var result []string
for _, item := range items {
if item != "" {
result = append(result, item)
}
}
return result
}