Skip to content

Commit

Permalink
Merge pull request #145 from mklimuk/chore/struct_regex_matcher
Browse files Browse the repository at this point in the history
chore: avoid recompiling struct tag matching regexes
  • Loading branch information
mefellows authored Jul 29, 2020
2 parents ae112ff + e25aa73 commit aa6e2d2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions dsl/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ const (

var timeExample = time.Date(2000, 2, 1, 12, 30, 0, 0, time.UTC)

var fullRegex = regexp.MustCompile(`regex=(.*)$`)
var exampleRegex = regexp.MustCompile(`^example=(.*)`)

type eachLike struct {
Contents interface{} `json:"contents"`
Min int `json:"min"`
Expand Down Expand Up @@ -421,9 +424,6 @@ func pluckParams(srcType reflect.Type, pactTag string) params {
triggerInvalidPactTagPanic(pactTag, err)
}
case reflect.String:
fullRegex, _ := regexp.Compile(`regex=(.*)$`)
exampleRegex, _ := regexp.Compile(`^example=(.*)`)

if fullRegex.Match([]byte(pactTag)) {
components := strings.Split(pactTag, ",regex=")

Expand Down

0 comments on commit aa6e2d2

Please sign in to comment.