Module organization requires a better structure to decouple definitions and implementations
31 lines
550 B
Go
31 lines
550 B
Go
// 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)
|
|
}
|