A Distributed RESTful and Plugable Matching Engine.
WIP.
func main() {
config := synapse.Config{}
err := config.LoadYAML("synapse.yaml")
if err != nil {
panic(err)
}
syn, err := synapse.NewSynapse(config)
if err != nil {
panic(err)
}
ctx := synapse.Context{"user_id": "1"}
hits, err := syn.Match("users_products", ctx)
if err != nil {
panic(err)
}
fmt.Printf("%v\n", hits.IDs) // [10 15 30]
}
plugin_dir: plugins
matchers:
-
name: users_products
profilers:
-
name: profiler
version: 0.0.1
associator:
name: associator
version: 0.0.1
searcher:
name: searcher
version: 0.0.1
Synapse selects the matching algorithm by Router. Matching algorithms are provided as plugins and distributed processing is also possible.
Matcher is composed of profilers, associator and searcher. This is provided as a plugin.
Profilers are filter group that converts subject and context into profile. Associator is a filter that associates profile and context with cluster. Searcher is a filter that searches for cluster using context, profile and association. This also sorts the search results.
You can prepare custom plugins. Plugins must be implemented as Profiler or Associator or Searcher interface, and be published with permitted function names, "NewProfiler", "NewAssociator" and "NewSearcher".
package main
import "github.com/monochromegane/synapse"
type profiler struct {
}
// Implement interface
func (p *profiler) Profile(ctx synapse.Context) (synapse.Profile, error) {
return synapse.Profile{}, nil
}
func (p *profiler) Initialize() error {
return nil
}
func (p *profiler) Finalize() error {
return nil
}
// Export new func
func NewProfiler() synapse.Profiler {
return &profiler{}
}
And build as plugin.
$ go build -buildmode=plugin -o PLUGIN_NAME.so.x.x.x PLUGIN_NAME.go