mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
621 B
32 lines
621 B
9 years ago
|
package router
|
||
9 years ago
|
|
||
9 years ago
|
import (
|
||
|
"errors"
|
||
|
)
|
||
|
|
||
|
type ConfigObjectCreator func([]byte) (interface{}, error)
|
||
9 years ago
|
|
||
|
var (
|
||
|
configCache map[string]ConfigObjectCreator
|
||
9 years ago
|
|
||
|
ErrorRouterNotFound = errors.New("Router not found.")
|
||
9 years ago
|
)
|
||
|
|
||
|
func RegisterRouterConfig(strategy string, creator ConfigObjectCreator) error {
|
||
|
// TODO: check strategy
|
||
|
configCache[strategy] = creator
|
||
|
return nil
|
||
|
}
|
||
|
|
||
9 years ago
|
func CreateRouterConfig(strategy string, data []byte) (interface{}, error) {
|
||
9 years ago
|
creator, found := configCache[strategy]
|
||
|
if !found {
|
||
9 years ago
|
return nil, ErrorRouterNotFound
|
||
9 years ago
|
}
|
||
9 years ago
|
return creator(data)
|
||
9 years ago
|
}
|
||
|
|
||
|
func init() {
|
||
|
configCache = make(map[string]ConfigObjectCreator)
|
||
|
}
|