mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Clean up/make consistent the APIs for registering core components, make Docker an optional component at compile time (#1111)
This commit is contained in:
26
api/agent/drivers/register.go
Normal file
26
api/agent/drivers/register.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package drivers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type DriverFunc func(config Config) (Driver, error)
|
||||
|
||||
var drivers = make(map[string]DriverFunc)
|
||||
|
||||
// Register adds a container driver by name to this process
|
||||
func Register(name string, driverFunc DriverFunc) {
|
||||
logrus.Infof("Registering container driver '%s'", name)
|
||||
drivers[name] = driverFunc
|
||||
}
|
||||
|
||||
// New Instantiates a driver by name
|
||||
func New(driverName string, config Config) (Driver, error) {
|
||||
driverFunc, ok := drivers[driverName]
|
||||
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("agent driver \"%s\" is not registered", driverName)
|
||||
}
|
||||
return driverFunc(config)
|
||||
}
|
||||
Reference in New Issue
Block a user