From 0a8e283e55f3bc56834301c61654a209001fb287 Mon Sep 17 00:00:00 2001 From: V2Ray Date: Tue, 3 Nov 2015 23:24:56 +0100 Subject: [PATCH] function to create router --- app/router/router.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/app/router/router.go b/app/router/router.go index af9c18e2d..51bd007f6 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -1,10 +1,16 @@ package router import ( + "errors" + "github.com/v2ray/v2ray-core/app/point/config" v2net "github.com/v2ray/v2ray-core/common/net" ) +var ( + RouterNotFound = errors.New("Router not found.") +) + type Router interface { TakeDetour(v2net.Packet) (config.ConnectionTag, error) } @@ -22,3 +28,10 @@ func RegisterRouter(name string, factory RouterFactory) error { 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, RouterNotFound +}