1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-06 18:28:00 -05:00
v2fly/app/router/config_cache.go
2016-01-17 15:20:49 +00:00

32 lines
621 B
Go

package router
import (
"errors"
)
type ConfigObjectCreator func([]byte) (interface{}, error)
var (
configCache map[string]ConfigObjectCreator
ErrorRouterNotFound = 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, ErrorRouterNotFound
}
return creator(data)
}
func init() {
configCache = make(map[string]ConfigObjectCreator)
}