37 lines
759 B
Go
37 lines
759 B
Go
package registry
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.maximhutz.com/max/lambda/pkg/engine"
|
|
)
|
|
|
|
type Engine interface {
|
|
Load() Process
|
|
Name() string
|
|
InType() string
|
|
}
|
|
|
|
type convertedEngine[T any] struct {
|
|
engine engine.Engine[T]
|
|
name string
|
|
inType string
|
|
}
|
|
|
|
func (e convertedEngine[T]) InType() string { return e.inType }
|
|
|
|
func (e convertedEngine[T]) Name() string { return e.name }
|
|
|
|
func (e convertedEngine[T]) Load() Process {
|
|
return convertedProcess[T]{e.engine.Load(), e.inType}
|
|
}
|
|
|
|
func RegisterEngine[T any](registry *Registry, e engine.Engine[T], name, inType string) error {
|
|
if _, ok := registry.engines[name]; ok {
|
|
return fmt.Errorf("engine '%s' already registered", name)
|
|
}
|
|
|
|
registry.engines[name] = &convertedEngine[T]{e, name, inType}
|
|
return nil
|
|
}
|