From 19c6d7d183354ea39ff8fd829870745082a55644 Mon Sep 17 00:00:00 2001 From: what Date: Tue, 31 Oct 2023 10:59:17 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E8=B0=83=E6=95=B4=20GoPluginCore=20?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E6=B3=A8=E5=86=8C=E5=85=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support/service.go | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/support/service.go b/support/service.go index 03e1186..47e5c5c 100644 --- a/support/service.go +++ b/support/service.go @@ -6,23 +6,46 @@ import ( "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) if err != nil { panic(err) } - if f, err := p.Lookup("RegControllers"); err != nil { - panic(err) - } else if fn, ok := f.(func(map[string]contracts.Controller) error); ok { - fn(controllers) - } - - if f, err := p.Lookup("RegListens"); err != nil { - panic(err) - } else if fn, ok := f.(func(map[string]contracts.ResListener) error); ok { - fn(listens) + 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 { + panic(err) + } else if fn, ok := f.(func(map[string]contracts.Controller) error); ok { + fn(s) + } + case map[string]contracts.ResListener: + if f, err := p.Lookup("RegListens"); err != nil { + panic(err) + } else if fn, ok := f.(func(map[string]contracts.ResListener) error); ok { + 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 {