mirror of
https://github.com/v2ray/v2ray-core.git
synced 2026-11-01 08:17:25 +00:00
simplify app design
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"v2ray.com/core/app"
|
||||
"v2ray.com/core/app/proxyman"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/proxy"
|
||||
)
|
||||
|
||||
@@ -60,10 +60,6 @@ func (v OutboundHandlerManagerFactory) Create(space app.Space, config interface{
|
||||
return New(), nil
|
||||
}
|
||||
|
||||
func (v OutboundHandlerManagerFactory) AppId() app.ID {
|
||||
return proxyman.APP_ID_OUTBOUND_MANAGER
|
||||
}
|
||||
|
||||
func init() {
|
||||
app.RegisterApplicationFactory(serial.GetMessageType(new(proxyman.OutboundConfig)), OutboundHandlerManagerFactory{})
|
||||
common.Must(app.RegisterApplicationFactory((*proxyman.OutboundConfig)(nil), OutboundHandlerManagerFactory{}))
|
||||
}
|
||||
|
||||
@@ -3,14 +3,10 @@ package proxyman
|
||||
|
||||
import (
|
||||
"v2ray.com/core/app"
|
||||
"v2ray.com/core/common/serial"
|
||||
"v2ray.com/core/proxy"
|
||||
)
|
||||
|
||||
const (
|
||||
APP_ID_INBOUND_MANAGER = app.ID(4)
|
||||
APP_ID_OUTBOUND_MANAGER = app.ID(6)
|
||||
)
|
||||
|
||||
type InboundHandlerManager interface {
|
||||
GetHandler(tag string) (proxy.InboundHandler, int)
|
||||
}
|
||||
@@ -21,3 +17,19 @@ type OutboundHandlerManager interface {
|
||||
SetDefaultHandler(handler proxy.OutboundHandler) error
|
||||
SetHandler(tag string, handler proxy.OutboundHandler) error
|
||||
}
|
||||
|
||||
func InboundHandlerManagerFromSpace(space app.Space) InboundHandlerManager {
|
||||
app := space.(app.AppGetter).GetApp(serial.GetMessageType((*InboundConfig)(nil)))
|
||||
if app == nil {
|
||||
return nil
|
||||
}
|
||||
return app.(InboundHandlerManager)
|
||||
}
|
||||
|
||||
func OutboundHandlerManagerFromSpace(space app.Space) OutboundHandlerManager {
|
||||
app := space.(app.AppGetter).GetApp(serial.GetMessageType((*OutboundConfig)(nil)))
|
||||
if app == nil {
|
||||
return nil
|
||||
}
|
||||
return app.(OutboundHandlerManager)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user