Compile takes our match expression as a string, and compiles it into a *Match object. Will return an error on an invalid pattern.
(pattern string)
| 20 | // Compile takes our match expression as a string, and compiles it into a *Match object. |
| 21 | // Will return an error on an invalid pattern. |
| 22 | func MatchCompile(pattern string) (*Match, error) { |
| 23 | // check for pattern in cache |
| 24 | matchCacheLock.RLock() |
| 25 | matcher, ok := matchCache[pattern] |
| 26 | matchCacheLock.RUnlock() |
| 27 | if ok { |
| 28 | return matcher, nil |
| 29 | } |
| 30 | |
| 31 | // pattern isn't in cache, compile it |
| 32 | matcher, err := matchCompile(pattern) |
| 33 | if err != nil { |
| 34 | return nil, err |
| 35 | } |
| 36 | // add it to the cache |
| 37 | matchCacheLock.Lock() |
| 38 | matchCache[pattern] = matcher |
| 39 | matchCacheLock.Unlock() |
| 40 | |
| 41 | return matcher, nil |
| 42 | } |
| 43 | |
| 44 | func matchCompile(pattern string) (match *Match, err error) { |
| 45 | regex := "" |
no test coverage detected