mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-10 02:53:12 +00:00
36 lines
1.2 KiB
Go
36 lines
1.2 KiB
Go
package inbound
|
|
|
|
import (
|
|
"context"
|
|
|
|
"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"
|
|
F "github.com/sagernet/sing/common/format"
|
|
)
|
|
|
|
func New(ctx context.Context, router adapter.Router, logger log.Logger, index int, options option.Inbound) (adapter.Inbound, error) {
|
|
var tag string
|
|
if options.Tag != "" {
|
|
tag = options.Tag
|
|
} else {
|
|
tag = F.ToString(index)
|
|
}
|
|
inboundLogger := logger.WithPrefix(F.ToString("inbound/", options.Type, "[", tag, "]: "))
|
|
switch options.Type {
|
|
case C.TypeDirect:
|
|
return NewDirect(ctx, router, inboundLogger, options.Tag, options.DirectOptions), nil
|
|
case C.TypeSocks:
|
|
return NewSocks(ctx, router, inboundLogger, options.Tag, options.SocksOptions), nil
|
|
case C.TypeHTTP:
|
|
return NewHTTP(ctx, router, inboundLogger, options.Tag, options.HTTPOptions), nil
|
|
case C.TypeMixed:
|
|
return NewMixed(ctx, router, inboundLogger, options.Tag, options.MixedOptions), nil
|
|
case C.TypeShadowsocks:
|
|
return NewShadowsocks(ctx, router, inboundLogger, options.Tag, options.ShadowsocksOptions)
|
|
default:
|
|
panic(F.ToString("unknown inbound type: ", options.Type))
|
|
}
|
|
}
|