1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-02-20 23:47:21 -05:00
v2fly/proxy/handler_cache.go

34 lines
766 B
Go
Raw Normal View History

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