mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-12-26 12:45:39 +08:00
29 lines
943 B
Go
29 lines
943 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"
|
|
F "github.com/sagernet/sing/common/format"
|
|
)
|
|
|
|
func New(router adapter.Router, logger log.Logger, index int, options option.Outbound) (adapter.Outbound, error) {
|
|
var tag string
|
|
if options.Tag != "" {
|
|
tag = options.Tag
|
|
} else {
|
|
tag = F.ToString(index)
|
|
}
|
|
outboundLogger := logger.WithPrefix(F.ToString("outbound/", options.Type, "[", tag, "]: "))
|
|
switch options.Type {
|
|
case C.TypeDirect:
|
|
return NewDirect(router, outboundLogger, options.Tag, common.PtrValueOrDefault(options.DirectOptions)), nil
|
|
case C.TypeShadowsocks:
|
|
return NewShadowsocks(router, outboundLogger, options.Tag, common.PtrValueOrDefault(options.ShadowsocksOptions))
|
|
default:
|
|
panic(F.ToString("unknown outbound type: ", options.Type))
|
|
}
|
|
}
|