[feat] 调整 GoPluginCore 服务注册入口

This commit is contained in:
what 2023-10-31 10:59:17 +08:00
parent 138c9f226d
commit 19c6d7d183

View File

@ -6,23 +6,46 @@ import (
"git.fsdpf.net/go/contracts" "git.fsdpf.net/go/contracts"
) )
func GoPluginCore(core string, controllers map[string]contracts.Controller, listens map[string]contracts.ResListener) { func GoPluginCore(core string, services ...any) {
p, err := plugin.Open(core) p, err := plugin.Open(core)
if err != nil { if err != nil {
panic(err) panic(err)
} }
for i := 0; i < len(services); i++ {
switch s := services[i].(type) {
case map[string]contracts.Controller:
if f, err := p.Lookup("RegControllers"); err != nil { if f, err := p.Lookup("RegControllers"); err != nil {
panic(err) panic(err)
} else if fn, ok := f.(func(map[string]contracts.Controller) error); ok { } else if fn, ok := f.(func(map[string]contracts.Controller) error); ok {
fn(controllers) fn(s)
} }
case map[string]contracts.ResListener:
if f, err := p.Lookup("RegListens"); err != nil { if f, err := p.Lookup("RegListens"); err != nil {
panic(err) panic(err)
} else if fn, ok := f.(func(map[string]contracts.ResListener) error); ok { } else if fn, ok := f.(func(map[string]contracts.ResListener) error); ok {
fn(listens) fn(s)
}
case map[string]contracts.GRpc:
if f, err := p.Lookup("RegGRpcs"); err != nil {
panic(err)
} else if fn, ok := f.(func(map[string]contracts.GRpc) error); ok {
fn(s)
}
case map[string]contracts.Job:
if f, err := p.Lookup("RegJobs"); err != nil {
panic(err)
} else if fn, ok := f.(func(map[string]contracts.Job) error); ok {
fn(s)
}
case map[string]contracts.Cron:
if f, err := p.Lookup("RegCrons"); err != nil {
panic(err)
} else if fn, ok := f.(func(map[string]contracts.Cron) error); ok {
fn(s)
}
}
} }
if f, err := p.Lookup("Run"); err != nil { if f, err := p.Lookup("Run"); err != nil {