1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-31 06:26:53 -05:00
v2fly/proxy/handler_cache.go
2017-01-12 12:54:34 +01:00

46 lines
1.3 KiB
Go

package proxy
import (
"v2ray.com/core/app"
"v2ray.com/core/common"
"v2ray.com/core/common/errors"
)
var (
inboundFactories = make(map[string]InboundHandlerFactory)
outboundFactories = make(map[string]OutboundHandlerFactory)
)
func RegisterInboundHandlerCreator(name string, creator InboundHandlerFactory) error {
if _, found := inboundFactories[name]; found {
return common.ErrDuplicatedName
}
inboundFactories[name] = creator
return nil
}
func RegisterOutboundHandlerCreator(name string, creator OutboundHandlerFactory) error {
if _, found := outboundFactories[name]; found {
return common.ErrDuplicatedName
}
outboundFactories[name] = creator
return nil
}
func CreateInboundHandler(name string, space app.Space, config interface{}, meta *InboundHandlerMeta) (InboundHandler, error) {
creator, found := inboundFactories[name]
if !found {
return nil, errors.New("Proxy: Unknown inbound name: " + name)
}
return creator.Create(space, config, meta)
}
func CreateOutboundHandler(name string, space app.Space, config interface{}, meta *OutboundHandlerMeta) (OutboundHandler, error) {
creator, found := outboundFactories[name]
if !found {
return nil, errors.New("Proxy: Unknown outbound name: " + name)
}
return creator.Create(space, config, meta)
}