Invalid config check

This commit is contained in:
世界
2022-07-03 01:57:04 +08:00
parent 6eae8e361f
commit 30444057bd
16 changed files with 276 additions and 162 deletions

View File

@@ -8,10 +8,14 @@ import (
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"
"github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions"
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) {
if common.IsEmptyByEquals(options) {
return nil, E.New("empty inbound config")
}
var tag string
if options.Tag != "" {
tag = options.Tag
@@ -21,16 +25,16 @@ func New(ctx context.Context, router adapter.Router, logger log.Logger, index in
inboundLogger := logger.WithPrefix(F.ToString("inbound/", options.Type, "[", tag, "]: "))
switch options.Type {
case C.TypeDirect:
return NewDirect(ctx, router, inboundLogger, options.Tag, common.PtrValueOrDefault(options.DirectOptions)), nil
return NewDirect(ctx, router, inboundLogger, options.Tag, options.DirectOptions), nil
case C.TypeSocks:
return NewSocks(ctx, router, inboundLogger, options.Tag, common.PtrValueOrDefault(options.SocksOptions)), nil
return NewSocks(ctx, router, inboundLogger, options.Tag, options.SocksOptions), nil
case C.TypeHTTP:
return NewHTTP(ctx, router, inboundLogger, options.Tag, common.PtrValueOrDefault(options.HTTPOptions)), nil
return NewHTTP(ctx, router, inboundLogger, options.Tag, options.HTTPOptions), nil
case C.TypeMixed:
return NewMixed(ctx, router, inboundLogger, options.Tag, common.PtrValueOrDefault(options.MixedOptions)), nil
return NewMixed(ctx, router, inboundLogger, options.Tag, options.MixedOptions), nil
case C.TypeShadowsocks:
return NewShadowsocks(ctx, router, inboundLogger, options.Tag, common.PtrValueOrDefault(options.ShadowsocksOptions))
return NewShadowsocks(ctx, router, inboundLogger, options.Tag, options.ShadowsocksOptions)
default:
panic(F.ToString("unknown inbound type: ", options.Type))
return nil, E.New("unknown inbound type: ", options.Type)
}
}