Skip to content

Commit 8ece11e

Browse files
committed
readLines: accept an io.Reader instead of a file path
1 parent 3342861 commit 8ece11e

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

main.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"crypto/tls"
66
"fmt"
7+
"io"
78
"net/http"
89
"net/url"
910
"os"
@@ -97,7 +98,14 @@ func main() {
9798
}
9899

99100
if *inputFileArg != "" {
100-
lines, err := readLines(*inputFileArg)
101+
f, err := os.Open(*inputFileArg)
102+
if err != nil {
103+
output.Error("[!] Couldn't open input file", err)
104+
return
105+
}
106+
defer f.Close()
107+
108+
lines, err := readLines(f)
101109
if err != nil {
102110
output.Error("[!] Couldn't read from input file", err)
103111
}
@@ -249,16 +257,9 @@ func getScriptSrc(url string, method string, headers []string, insecure bool, ti
249257
return sources, nil
250258
}
251259

252-
// ToDo: Use io.Writer instead of a file path
253-
func readLines(path string) ([]string, error) {
254-
file, err := os.Open(path)
255-
if err != nil {
256-
return nil, err
257-
}
258-
defer file.Close()
259-
260+
func readLines(r io.Reader) ([]string, error) {
260261
var lines []string
261-
scanner := bufio.NewScanner(file)
262+
scanner := bufio.NewScanner(r)
262263
for scanner.Scan() {
263264
lines = append(lines, scanner.Text())
264265
}

0 commit comments

Comments
 (0)