Default targets to stdin and abstract file handling

This commit is contained in:
Tomás Senart
2013-09-11 14:10:45 +01:00
parent 3059854751
commit 7cd13327c6
6 changed files with 50 additions and 73 deletions

View File

@@ -6,25 +6,14 @@ import (
"io"
"math/rand"
"net/http"
"os"
"strings"
)
// Targets represents the http.Requests which will be issued during the test
type Targets []*http.Request
// NewTargetsFromFile reads and parses targets from a text file
func NewTargetsFromFile(filename string) (Targets, error) {
file, err := os.Open(filename)
if err != nil {
return Targets{}, err
}
defer file.Close()
return readTargets(file)
}
// readTargets reads targets out of a line separated source skipping empty lines
func readTargets(source io.Reader) (Targets, error) {
// NewTargetsFrom reads targets out of a line separated source skipping empty lines
func NewTargetsFrom(source io.Reader) (Targets, error) {
scanner := bufio.NewScanner(source)
lines := make([]string, 0)
for scanner.Scan() {