-
Notifications
You must be signed in to change notification settings - Fork 171
/
schema_matcher.go
47 lines (37 loc) · 1002 Bytes
/
schema_matcher.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
package matchers
import (
"github.com/juju/errors"
"github.com/moiot/gravity/pkg/core"
"github.com/moiot/gravity/pkg/registry"
"github.com/moiot/gravity/pkg/utils"
)
const SchemaMatcherName = "match-schema"
type SchemaMatcher struct {
SchemaGlob string
}
func (m *SchemaMatcher) Configure(data interface{}) error {
if arg, ok := data.(string); !ok {
return errors.Errorf("match-schema only receives a string value, you provided: %v", data)
} else {
m.SchemaGlob = arg
return nil
}
}
func (m *SchemaMatcher) Match(msg *core.Msg) bool {
if utils.Glob(m.SchemaGlob, msg.Database) {
return true
} else {
return false
}
}
type schemaMatcherFactoryType struct {
}
func (f *schemaMatcherFactoryType) Configure(_ string, _ map[string]interface{}) error {
return nil
}
func (f *schemaMatcherFactoryType) NewMatcher() core.IMatcher {
return &SchemaMatcher{}
}
func init() {
registry.RegisterPlugin(registry.MatcherPlugin, SchemaMatcherName, &schemaMatcherFactoryType{}, true)
}