v2ray-core/app/router/config_cache.go

30 lines
585 B
Go
Raw Normal View History

2016-01-17 15:20:49 +00:00
package router
2015-11-14 13:24:56 +00:00
2016-01-17 15:20:49 +00:00
import (
2016-08-20 18:55:45 +00:00
"v2ray.com/core/common"
2016-01-17 15:20:49 +00:00
)
type ConfigObjectCreator func([]byte) (interface{}, error)
2015-11-14 13:24:56 +00:00
var (
configCache map[string]ConfigObjectCreator
)
func RegisterRouterConfig(strategy string, creator ConfigObjectCreator) error {
// TODO: check strategy
configCache[strategy] = creator
return nil
}
2016-01-17 15:20:49 +00:00
func CreateRouterConfig(strategy string, data []byte) (interface{}, error) {
2015-11-14 13:24:56 +00:00
creator, found := configCache[strategy]
if !found {
2016-08-18 06:34:21 +00:00
return nil, common.ErrObjectNotFound
2015-11-14 13:24:56 +00:00
}
2016-01-17 15:20:49 +00:00
return creator(data)
2015-11-14 13:24:56 +00:00
}
func init() {
configCache = make(map[string]ConfigObjectCreator)
}