2016-12-15 09:46:20 -05:00
|
|
|
package proxy
|
2016-01-02 17:08:36 -05:00
|
|
|
|
|
|
|
import (
|
2017-01-12 18:56:21 -05:00
|
|
|
"context"
|
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/common"
|
2016-12-04 03:10:47 -05:00
|
|
|
"v2ray.com/core/common/errors"
|
2016-01-02 17:08:36 -05:00
|
|
|
)
|
|
|
|
|
2017-01-12 18:56:21 -05:00
|
|
|
func CreateInboundHandler(ctx context.Context, config interface{}) (InboundHandler, error) {
|
|
|
|
handler, err := common.CreateObject(ctx, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-01-02 17:08:36 -05:00
|
|
|
}
|
2017-01-12 18:56:21 -05:00
|
|
|
switch h := handler.(type) {
|
|
|
|
case InboundHandler:
|
|
|
|
return h, nil
|
|
|
|
default:
|
|
|
|
return nil, errors.New("Proxy: Not a InboundHandler.")
|
2016-01-02 17:08:36 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-12 18:56:21 -05:00
|
|
|
func CreateOutboundHandler(ctx context.Context, config interface{}) (OutboundHandler, error) {
|
|
|
|
handler, err := common.CreateObject(ctx, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-01-02 17:08:36 -05:00
|
|
|
}
|
2017-01-12 18:56:21 -05:00
|
|
|
switch h := handler.(type) {
|
|
|
|
case OutboundHandler:
|
|
|
|
return h, nil
|
|
|
|
default:
|
|
|
|
return nil, errors.New("Proxy: Not a OutboundHandler.")
|
2016-01-02 17:08:36 -05:00
|
|
|
}
|
|
|
|
}
|