Clean up/make consistent the APIs for registering core components, make Docker an optional component at compile time (#1111)

This commit is contained in:
Owen Cliffe
2018-07-07 10:37:19 +01:00
committed by GitHub
parent cc468afeec
commit fff95e7992
15 changed files with 62 additions and 20 deletions

View 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)
}