mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-14 04:43:17 +00:00
31 lines
1,002 B
Go
31 lines
1,002 B
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"
|
|
"github.com/sagernet/sing/common"
|
|
E "github.com/sagernet/sing/common/exceptions"
|
|
)
|
|
|
|
func New(router adapter.Router, logger log.ContextLogger, options option.Outbound) (adapter.Outbound, error) {
|
|
if common.IsEmpty(options) {
|
|
return nil, E.New("empty outbound config")
|
|
}
|
|
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.TypeSocks:
|
|
return NewSocks(router, logger, options.Tag, options.SocksOptions)
|
|
case C.TypeHTTP:
|
|
return NewHTTP(router, logger, options.Tag, options.HTTPOptions), nil
|
|
case C.TypeShadowsocks:
|
|
return NewShadowsocks(router, logger, options.Tag, options.ShadowsocksOptions)
|
|
default:
|
|
return nil, E.New("unknown outbound type: ", options.Type)
|
|
}
|
|
}
|