1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-07 02:38:10 -05:00
v2fly/app/router/router.go

31 lines
609 B
Go
Raw Normal View History

2015-10-28 18:18:07 -04:00
package router
import (
v2net "github.com/v2ray/v2ray-core/common/net"
)
type Router interface {
TakeDetour(v2net.Destination) (string, error)
2015-10-28 18:18:07 -04: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 17:24:56 -05:00
func CreateRouter(name string, rawConfig interface{}) (Router, error) {
if factory, found := routerCache[name]; found {
return factory.Create(rawConfig)
}
2016-01-30 06:23:56 -05:00
return nil, ErrorRouterNotFound
2015-11-03 17:24:56 -05:00
}