Skip to content

Commit

Permalink
Merge pull request #22 from c-bata/replace-option
Browse files Browse the repository at this point in the history
Add replace config option
  • Loading branch information
matsuu committed Sep 4, 2019
2 parents e4a42f9 + 72bcfb1 commit 52f3328
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
28 changes: 28 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type tomlConfig struct {
StatusIndex int `toml:"status_index"`
DurationIndex int `toml:"duration_index"`
Bundle []bundleConfig
Replace []replaceConfig
Bundles map[string]bundleConfig // for backward compatibility

ShowBytes bool `toml:"show_bytes"`
Expand All @@ -41,6 +42,11 @@ type bundleConfig struct {
Regexp string
}

type replaceConfig struct {
Regexp string
Replace string
}

type Measure struct {
Url string
Count int
Expand Down Expand Up @@ -387,6 +393,25 @@ func main() {
for _, b := range config.Bundles {
chBundle <- b
}

type replaceRegexp struct {
compiledRegexp *regexp.Regexp
replace string
}
urlReplaceRegexps := make([]*replaceRegexp, 0, len(config.Replace))
chReplace := make(chan replaceConfig)
go func() {
for replace := range chReplace {
urlReplaceRegexps = append(urlReplaceRegexps, &replaceRegexp{
compiledRegexp: regexp.MustCompile(replace.Regexp),
replace: replace.Replace,
})
}
done <- struct{}{}
}()
for _, r := range config.Replace {
chReplace <- r
}
close(chBundle)
<-done

Expand Down Expand Up @@ -442,6 +467,9 @@ func main() {
break
}
}
for _, replace := range urlReplaceRegexps {
url = replace.compiledRegexp.ReplaceAllString(url, replace.replace)
}
time, err := strconv.ParseFloat(s[config.DurationIndex], 10)
if err == nil {
time = time * scale
Expand Down
18 changes: 18 additions & 0 deletions toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,22 @@ name = "stylesheets"
[[bundle]]
regexp = '^(GET|HEAD) /images/'
name = "images"
# You can replace the part of urls which matched to your regular expressions.
# For overview of regexp syntax: https://golang.org/pkg/regexp/syntax/
#[[replace]]
#regexp = '/[0-9]+/'
#replace = '/<num>/'
#
#[[replace]]
#regexp = '/[0-9]+\s'
#replace = '/<num> '
#
#[[replace]]
#regexp = '=[0-9]+&'
#replace = '=<num>&'
#
#[[replace]]
#regexp = '=[0-9]+\s'
#replace = '=<num> '
`

0 comments on commit 52f3328

Please sign in to comment.