2016-12-15 14:46:20 +00:00
|
|
|
package proxy
|
2016-01-02 22:08:36 +00:00
|
|
|
|
|
|
|
import (
|
2017-01-12 23:56:21 +00:00
|
|
|
"context"
|
|
|
|
|
2016-08-20 18:55:45 +00:00
|
|
|
"v2ray.com/core/common"
|
2016-01-02 22:08:36 +00:00
|
|
|
)
|
|
|
|
|
2017-01-26 19:57:18 +00:00
|
|
|
func CreateInboundHandler(ctx context.Context, config interface{}) (Inbound, error) {
|
2017-01-12 23:56:21 +00:00
|
|
|
handler, err := common.CreateObject(ctx, config)
|
|
|
|
if err != nil {
|
2017-07-25 21:12:54 +00:00
|
|
|
return nil, newError("failed to create inbound handler").Base(err)
|
2016-01-02 22:08:36 +00:00
|
|
|
}
|
2017-01-12 23:56:21 +00:00
|
|
|
switch h := handler.(type) {
|
2017-01-26 19:57:18 +00:00
|
|
|
case Inbound:
|
2017-01-12 23:56:21 +00:00
|
|
|
return h, nil
|
|
|
|
default:
|
2017-04-09 13:04:04 +00:00
|
|
|
return nil, newError("not a InboundHandler")
|
2016-01-02 22:08:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-26 19:57:18 +00:00
|
|
|
func CreateOutboundHandler(ctx context.Context, config interface{}) (Outbound, error) {
|
2017-01-12 23:56:21 +00:00
|
|
|
handler, err := common.CreateObject(ctx, config)
|
|
|
|
if err != nil {
|
2017-07-25 21:12:54 +00:00
|
|
|
return nil, newError("failed to create outbound handler").Base(err)
|
2016-01-02 22:08:36 +00:00
|
|
|
}
|
2017-01-12 23:56:21 +00:00
|
|
|
switch h := handler.(type) {
|
2017-01-26 19:57:18 +00:00
|
|
|
case Outbound:
|
2017-01-12 23:56:21 +00:00
|
|
|
return h, nil
|
|
|
|
default:
|
2017-04-09 13:04:04 +00:00
|
|
|
return nil, newError("not a OutboundHandler")
|
2016-01-02 22:08:36 +00:00
|
|
|
}
|
|
|
|
}
|