graceful shutdown, CoreInterface changes, MongoDB official driver is the only DB backend

This commit is contained in:
Darko Luketic
2020-05-06 01:49:46 +02:00
parent b722cb8a62
commit 58609926b9
6 changed files with 277 additions and 175 deletions

View File

@ -1,5 +1,10 @@
package main
import (
"fmt"
"github.com/davecgh/go-spew/spew"
)
type PluginRegistry struct {
CorePlugin map[string]CoreInterface
HandlerPlugin map[string]HandlerInterface
@ -13,6 +18,7 @@ func NewPluginRegistry() *PluginRegistry {
}
func (r *PluginRegistry) RegisterCorePlugin(plugin CoreInterface) error {
spew.Dump(plugin)
name, e := plugin.Register()
if e != nil {
return e
@ -45,3 +51,34 @@ func (r *PluginRegistry) RemoveCorePlugin(name string) {
func (r *PluginRegistry) RemoveHandlerPlugin(name string) {
delete(r.HandlerPlugin, name)
}
func (r *PluginRegistry) Run() error {
for _, v := range r.CorePlugin {
if e := v.BeforeRun(); e != nil {
return e
}
}
for _, v := range r.CorePlugin {
if e := v.Run(); e != nil {
return e
}
}
for _, v := range r.CorePlugin {
if e := v.AfterRun(); e != nil {
return e
}
}
return nil
}
func (r *PluginRegistry) Shutdown() {
fmt.Println("Registry: Shutdown")
spew.Dump(r.CorePlugin)
for k, v := range r.CorePlugin {
fmt.Println(k, v)
if e := v.UnRegister(); e != nil {
panic(e)
}
}
fmt.Println("Registry: Shutdown Done")
}