graceful shutdown, CoreInterface changes, MongoDB official driver is the only DB backend
This commit is contained in:
37
registry.go
37
registry.go
@ -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")
|
||||
}
|
||||
|
Reference in New Issue
Block a user