first plugin support.
Module organization requires a better structure to decouple definitions and implementations
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||
// All rights reserved.
|
||||
|
||||
// plugin.go
|
||||
package expr
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"plugin"
|
||||
)
|
||||
|
||||
var pluginRegister map[string]*plugin.Plugin
|
||||
|
||||
func registerPlugin(name string, p *plugin.Plugin) (err error) {
|
||||
if pluginExists(name) {
|
||||
err = fmt.Errorf("plugin %q already loaded", name)
|
||||
} else {
|
||||
pluginRegister[name] = p
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func pluginExists(name string) (exists bool) {
|
||||
_, exists = pluginRegister[name]
|
||||
return
|
||||
}
|
||||
|
||||
func init() {
|
||||
pluginRegister = make(map[string]*plugin.Plugin)
|
||||
}
|
||||
Reference in New Issue
Block a user