handler_cache.go 715 B

12345678910111213141516171819202122232425262728293031323334
  1. package proxy
  2. import (
  3. "context"
  4. "v2ray.com/core/common"
  5. "v2ray.com/core/common/errors"
  6. )
  7. func CreateInboundHandler(ctx context.Context, config interface{}) (Inbound, error) {
  8. handler, err := common.CreateObject(ctx, config)
  9. if err != nil {
  10. return nil, err
  11. }
  12. switch h := handler.(type) {
  13. case Inbound:
  14. return h, nil
  15. default:
  16. return nil, errors.New("Proxy: Not a InboundHandler.")
  17. }
  18. }
  19. func CreateOutboundHandler(ctx context.Context, config interface{}) (Outbound, error) {
  20. handler, err := common.CreateObject(ctx, config)
  21. if err != nil {
  22. return nil, err
  23. }
  24. switch h := handler.(type) {
  25. case Outbound:
  26. return h, nil
  27. default:
  28. return nil, errors.New("Proxy: Not a OutboundHandler.")
  29. }
  30. }