2016-01-17 10:20:49 -05:00
|
|
|
package router
|
2015-11-14 08:24:56 -05:00
|
|
|
|
2016-01-17 10:20:49 -05:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ConfigObjectCreator func([]byte) (interface{}, error)
|
2015-11-14 08:24:56 -05:00
|
|
|
|
|
|
|
var (
|
|
|
|
configCache map[string]ConfigObjectCreator
|
2016-01-17 10:20:49 -05:00
|
|
|
|
|
|
|
ErrorRouterNotFound = errors.New("Router not found.")
|
2015-11-14 08:24:56 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func RegisterRouterConfig(strategy string, creator ConfigObjectCreator) error {
|
|
|
|
// TODO: check strategy
|
|
|
|
configCache[strategy] = creator
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-01-17 10:20:49 -05:00
|
|
|
func CreateRouterConfig(strategy string, data []byte) (interface{}, error) {
|
2015-11-14 08:24:56 -05:00
|
|
|
creator, found := configCache[strategy]
|
|
|
|
if !found {
|
2016-01-17 10:20:49 -05:00
|
|
|
return nil, ErrorRouterNotFound
|
2015-11-14 08:24:56 -05:00
|
|
|
}
|
2016-01-17 10:20:49 -05:00
|
|
|
return creator(data)
|
2015-11-14 08:24:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
configCache = make(map[string]ConfigObjectCreator)
|
|
|
|
}
|