1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-29 02:35:23 +00:00
v2fly/app/router/router.go

31 lines
609 B
Go
Raw Normal View History

2015-10-28 22:18:07 +00:00
package router
import (
v2net "github.com/v2ray/v2ray-core/common/net"
)
type Router interface {
TakeDetour(v2net.Destination) (string, error)
2015-10-28 22:18:07 +00:00
}
type RouterFactory interface {
Create(rawConfig interface{}) (Router, error)
}
var (
routerCache = make(map[string]RouterFactory)
)
func RegisterRouter(name string, factory RouterFactory) error {
// TODO: check name
routerCache[name] = factory
return nil
}
2015-11-03 22:24:56 +00:00
func CreateRouter(name string, rawConfig interface{}) (Router, error) {
if factory, found := routerCache[name]; found {
return factory.Create(rawConfig)
}
2016-01-30 11:23:56 +00:00
return nil, ErrorRouterNotFound
2015-11-03 22:24:56 +00:00
}