github.com/hellofresh/janus@v0.0.0-20230925145208-ce8de8183c67/pkg/router/listen_path_matcher.go (about) 1 package router 2 3 import "regexp" 4 5 const ( 6 matchRule = `(\/\*(.+)?)` 7 ) 8 9 // ListenPathMatcher is responsible for matching a listen path to a set of rules 10 type ListenPathMatcher struct { 11 reg *regexp.Regexp 12 } 13 14 // NewListenPathMatcher creates a new instance ListenPathMatcher 15 func NewListenPathMatcher() *ListenPathMatcher { 16 return &ListenPathMatcher{regexp.MustCompile(matchRule)} 17 } 18 19 // Match verifies if a listen path matches the given rule 20 func (l *ListenPathMatcher) Match(listenPath string) bool { 21 return l.reg.MatchString(listenPath) 22 } 23 24 // Extract takes the usable part of the listen path based on the provided rule 25 func (l *ListenPathMatcher) Extract(listenPath string) string { 26 return l.reg.ReplaceAllString(listenPath, "") 27 }