| 12345678910111213141516171819202122232425262728293031 |
- package router
- import (
- "errors"
- )
- type ConfigObjectCreator func([]byte) (interface{}, error)
- var (
- configCache map[string]ConfigObjectCreator
- ErrRouterNotFound = errors.New("Router not found.")
- )
- func RegisterRouterConfig(strategy string, creator ConfigObjectCreator) error {
- // TODO: check strategy
- configCache[strategy] = creator
- return nil
- }
- func CreateRouterConfig(strategy string, data []byte) (interface{}, error) {
- creator, found := configCache[strategy]
- if !found {
- return nil, ErrRouterNotFound
- }
- return creator(data)
- }
- func init() {
- configCache = make(map[string]ConfigObjectCreator)
- }
|