From a1104e57d86b3d6e43a33fbe9f82668c1b56de3a Mon Sep 17 00:00:00 2001 From: what Date: Tue, 25 Apr 2023 17:08:36 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20add=20support.GoPluginCore=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- support/service.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 support/service.go diff --git a/support/service.go b/support/service.go new file mode 100644 index 0000000..03e1186 --- /dev/null +++ b/support/service.go @@ -0,0 +1,33 @@ +package support + +import ( + "plugin" + + "git.fsdpf.net/go/contracts" +) + +func GoPluginCore(core string, controllers map[string]contracts.Controller, listens map[string]contracts.ResListener) { + 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) + } + + if f, err := p.Lookup("Run"); err != nil { + panic(err) + } else if fn, ok := f.(func()); ok { + fn() + } +}