handler_cache.go 679 B

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