mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-11-02 17:27:50 -04:00
37 lines
674 B
Go
37 lines
674 B
Go
package router
|
|
|
|
import (
|
|
"errors"
|
|
|
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
|
)
|
|
|
|
var (
|
|
RouterNotFound = errors.New("Router not found.")
|
|
)
|
|
|
|
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, RouterNotFound
|
|
}
|