v2ray-core/proxy/handler_cache.go

35 lines
715 B
Go
Raw Normal View History

2016-12-15 14:46:20 +00:00
package proxy
2016-01-02 22:08:36 +00:00
import (
"context"
2016-08-20 18:55:45 +00:00
"v2ray.com/core/common"
2016-12-04 08:10:47 +00:00
"v2ray.com/core/common/errors"
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) {
handler, err := common.CreateObject(ctx, config)
if err != nil {
return nil, err
2016-01-02 22:08:36 +00:00
}
switch h := handler.(type) {
2017-01-26 19:57:18 +00:00
case Inbound:
return h, nil
default:
return nil, errors.New("Proxy: 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) {
handler, err := common.CreateObject(ctx, config)
if err != nil {
return nil, err
2016-01-02 22:08:36 +00:00
}
switch h := handler.(type) {
2017-01-26 19:57:18 +00:00
case Outbound:
return h, nil
default:
return nil, errors.New("Proxy: Not a OutboundHandler.")
2016-01-02 22:08:36 +00:00
}
}