sing-box/outbound/builder.go
2022-07-25 16:18:11 +08:00

38 lines
1.3 KiB
Go

package outbound
import (
"github.com/sagernet/sing-box/adapter"
C "github.com/sagernet/sing-box/constant"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
E "github.com/sagernet/sing/common/exceptions"
)
func New(router adapter.Router, logger log.ContextLogger, options option.Outbound) (adapter.Outbound, error) {
if options.Type == "" {
return nil, E.New("missing outbound type")
}
switch options.Type {
case C.TypeDirect:
return NewDirect(router, logger, options.Tag, options.DirectOptions), nil
case C.TypeBlock:
return NewBlock(logger, options.Tag), nil
case C.TypeDNS:
return NewDNS(router, logger, options.Tag), nil
case C.TypeSocks:
return NewSocks(router, logger, options.Tag, options.SocksOptions)
case C.TypeHTTP:
return NewHTTP(router, logger, options.Tag, options.HTTPOptions)
case C.TypeShadowsocks:
return NewShadowsocks(router, logger, options.Tag, options.ShadowsocksOptions)
case C.TypeVMess:
return NewVMess(router, logger, options.Tag, options.VMessOptions)
case C.TypeSelector:
return NewSelector(router, logger, options.Tag, options.SelectorOptions)
case C.TypeURLTest:
return NewURLTest(router, logger, options.Tag, options.URLTestOptions)
default:
return nil, E.New("unknown outbound type: ", options.Type)
}
}