1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-06 16:10:43 +00:00
v2fly/app/router/config_cache.go
2016-08-20 20:55:45 +02:00

30 lines
585 B
Go

package router
import (
"v2ray.com/core/common"
)
type ConfigObjectCreator func([]byte) (interface{}, error)
var (
configCache map[string]ConfigObjectCreator
)
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, common.ErrObjectNotFound
}
return creator(data)
}
func init() {
configCache = make(map[string]ConfigObjectCreator)
}