1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/app/router/router.go
2016-01-30 12:23:56 +01:00

31 lines
609 B
Go

package router
import (
v2net "github.com/v2ray/v2ray-core/common/net"
)
type Router interface {
TakeDetour(v2net.Destination) (string, error)
}
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
}
func CreateRouter(name string, rawConfig interface{}) (Router, error) {
if factory, found := routerCache[name]; found {
return factory.Create(rawConfig)
}
return nil, ErrorRouterNotFound
}