github.com/inazumav/sing-box@v0.0.0-20230926072359-ab51429a14f1/inbound/builder.go (about)

     1  package inbound
     2  
     3  import (
     4  	"context"
     5  	"github.com/inazumav/sing-box/experimental/libbox/platform"
     6  
     7  	"github.com/inazumav/sing-box/adapter"
     8  	C "github.com/inazumav/sing-box/constant"
     9  	"github.com/inazumav/sing-box/log"
    10  	"github.com/inazumav/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.TypeShadowsocks:
    20  		return NewShadowsocks(ctx, router, logger, options.Tag, options.ShadowsocksOptions)
    21  	case C.TypeVMess:
    22  		return NewVMess(ctx, router, logger, options.Tag, options.VMessOptions)
    23  	case C.TypeTrojan:
    24  		return NewTrojan(ctx, router, logger, options.Tag, options.TrojanOptions)
    25  	case C.TypeHysteria:
    26  		return NewHysteria(ctx, router, logger, options.Tag, options.HysteriaOptions)
    27  	case C.TypeVLESS:
    28  		return NewVLESS(ctx, router, logger, options.Tag, options.VLESSOptions)
    29  	case C.TypeTUIC:
    30  		return NewTUIC(ctx, router, logger, options.Tag, options.TUICOptions)
    31  	case C.TypeHysteria2:
    32  		return NewHysteria2(ctx, router, logger, options.Tag, options.Hysteria2Options)
    33  	default:
    34  		return nil, E.New("unknown inbound type: ", options.Type)
    35  	}
    36  }