Skip to content

Commit

Permalink
samples: limit support added
Browse files Browse the repository at this point in the history
  • Loading branch information
bfontaine committed Sep 7, 2015
1 parent ad09b86 commit e866a70
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
19 changes: 19 additions & 0 deletions samples/csv/csv.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ func executeRequest(reader *csv.Reader, query *charlatan.Query) {
fmt.Println("$")

var header []string
var limit int64

hasLimit := query.HasLimit()

if hasLimit {
limit = query.Limit()

if limit <= 0 {
return
}
}

line := 0

for {
Expand Down Expand Up @@ -86,6 +98,13 @@ func executeRequest(reader *csv.Reader, query *charlatan.Query) {
}

fmt.Println("# ", values)

if hasLimit {
limit--
if limit <= 0 {
break
}
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions samples/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ func fatalf(format string, args ...interface{}) {
}

func main() {
var limit int64

if len(os.Args) != 2 {
usage()
}
Expand All @@ -39,6 +41,16 @@ func main() {

decoder := json.NewDecoder(reader)

hasLimit := query.HasLimit()

if hasLimit {
limit = query.Limit()

if limit <= 0 {
return
}
}

line := 0

for {
Expand Down Expand Up @@ -72,5 +84,11 @@ func main() {
}

fmt.Println("# ", values)
if hasLimit {
limit--
if limit <= 0 {
break
}
}
}
}

0 comments on commit e866a70

Please sign in to comment.