mirror of
https://github.com/coredhcp/coredhcp.git
synced 2025-08-11 00:27:22 +02:00
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package plugins
|
|
|
|
import (
|
|
"github.com/coredhcp/coredhcp/handler"
|
|
"github.com/coredhcp/coredhcp/logger"
|
|
)
|
|
|
|
var log = logger.GetLogger()
|
|
|
|
// Plugin represents a plugin object.
|
|
// Setup6 and Setup4 are the setup functions for DHCPv6 and DHCPv4 handlers
|
|
// respectively. Both setup functions can be nil.
|
|
type Plugin struct {
|
|
Name string
|
|
Setup6 SetupFunc6
|
|
Setup4 SetupFunc4
|
|
}
|
|
|
|
// RegisteredPlugins maps a plugin name to a Plugin instance.
|
|
var RegisteredPlugins = make(map[string]*Plugin)
|
|
|
|
// SetupFunc6 defines a plugin setup function for DHCPv6
|
|
type SetupFunc6 func(args ...string) (handler.Handler6, error)
|
|
|
|
// SetupFunc4 defines a plugin setup function for DHCPv6
|
|
type SetupFunc4 func(args ...string) (handler.Handler4, error)
|
|
|
|
// RegisterPlugin registers a plugin by its name and setup functions.
|
|
func RegisterPlugin(name string, setup6 SetupFunc6, setup4 SetupFunc4) {
|
|
log.Printf("Registering plugin \"%s\"", name)
|
|
if _, ok := RegisteredPlugins[name]; ok {
|
|
// TODO this highlights that asking the plugins to register themselves
|
|
// is not the right approach. Need to register them in the main program.
|
|
log.Panicf("Plugin '%s' is already registered", name)
|
|
}
|
|
plugin := Plugin{
|
|
Name: name,
|
|
Setup6: setup6,
|
|
Setup4: setup4,
|
|
}
|
|
RegisteredPlugins[name] = &plugin
|
|
}
|