-
Notifications
You must be signed in to change notification settings - Fork 0
/
matchers.go
48 lines (41 loc) · 1.06 KB
/
matchers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package pubsub
import (
"strings"
)
// Match with attempt to match a topic with another topic using
// exactly the same topic.
func Match(topic string) func(string) bool {
return func(other string) bool {
return topic == other
}
}
// Any will always return true when matching a topic
func Any() func(string) bool {
return func(other string) bool {
return true
}
}
// Never will never match a topic
func Never() func(string) bool {
return func(other string) bool {
return false
}
}
// StartsWith will match a topic that starts with a certain string
func StartsWith(prefix string) func(string) bool {
return func(other string) bool {
return strings.HasPrefix(other, prefix)
}
}
// EndsWith will match a topic that ends with a certain string
func EndsWith(suffix string) func(string) bool {
return func(other string) bool {
return strings.HasSuffix(other, suffix)
}
}
// Contains will match a topic that contains a certain string
func Contains(value string) func(string) bool {
return func(other string) bool {
return strings.Contains(other, value)
}
}