github.com/sagernet/sing-box@v1.9.0-rc.20/inbound/builder.go (about) 1 package inbound 2 3 import ( 4 "context" 5 6 "github.com/sagernet/sing-box/adapter" 7 C "github.com/sagernet/sing-box/constant" 8 "github.com/sagernet/sing-box/experimental/libbox/platform" 9 "github.com/sagernet/sing-box/log" 10 "github.com/sagernet/sing-box/option" 11 E "github.com/sagernet/sing/common/exceptions" 12 ) 13 14 func New(ctx context.Context, router adapter.Router, logger log.ContextLogger, options option.Inbound, platformInterface platform.Interface) (adapter.Inbound, error) { 15 if options.Type == "" { 16 return nil, E.New("missing inbound type") 17 } 18 switch options.Type { 19 case C.TypeTun: 20 return NewTun(ctx, router, logger, options.Tag, options.TunOptions, platformInterface) 21 case C.TypeRedirect: 22 return NewRedirect(ctx, router, logger, options.Tag, options.RedirectOptions), nil 23 case C.TypeTProxy: 24 return NewTProxy(ctx, router, logger, options.Tag, options.TProxyOptions), nil 25 case C.TypeDirect: 26 return NewDirect(ctx, router, logger, options.Tag, options.DirectOptions), nil 27 case C.TypeSOCKS: 28 return NewSocks(ctx, router, logger, options.Tag, options.SocksOptions), nil 29 case C.TypeHTTP: 30 return NewHTTP(ctx, router, logger, options.Tag, options.HTTPOptions) 31 case C.TypeMixed: 32 return NewMixed(ctx, router, logger, options.Tag, options.MixedOptions), nil 33 case C.TypeShadowsocks: 34 return NewShadowsocks(ctx, router, logger, options.Tag, options.ShadowsocksOptions) 35 case C.TypeVMess: 36 return NewVMess(ctx, router, logger, options.Tag, options.VMessOptions) 37 case C.TypeTrojan: 38 return NewTrojan(ctx, router, logger, options.Tag, options.TrojanOptions) 39 case C.TypeNaive: 40 return NewNaive(ctx, router, logger, options.Tag, options.NaiveOptions) 41 case C.TypeHysteria: 42 return NewHysteria(ctx, router, logger, options.Tag, options.HysteriaOptions) 43 case C.TypeShadowTLS: 44 return NewShadowTLS(ctx, router, logger, options.Tag, options.ShadowTLSOptions) 45 case C.TypeVLESS: 46 return NewVLESS(ctx, router, logger, options.Tag, options.VLESSOptions) 47 case C.TypeTUIC: 48 return NewTUIC(ctx, router, logger, options.Tag, options.TUICOptions) 49 case C.TypeHysteria2: 50 return NewHysteria2(ctx, router, logger, options.Tag, options.Hysteria2Options) 51 default: 52 return nil, E.New("unknown inbound type: ", options.Type) 53 } 54 }