mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
27 lines
621 B
Go
27 lines
621 B
Go
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)
|
|
}
|