mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
validate config
This commit is contained in:
parent
53790153b0
commit
ced15857f3
@ -47,14 +47,26 @@ type subscriptionProvider struct {
|
|||||||
|
|
||||||
// NewSubscription creates a new subscription service.
|
// NewSubscription creates a new subscription service.
|
||||||
func NewSubscription(ctx context.Context, router adapter.Router, logger log.ContextLogger, logFactory log.Factory, options option.Service) (*Subscription, error) {
|
func NewSubscription(ctx context.Context, router adapter.Router, logger log.ContextLogger, logFactory log.Factory, options option.Service) (*Subscription, error) {
|
||||||
ctx2, cancel := context.WithCancel(ctx)
|
nproviders := len(options.SubscriptionOptions.Providers)
|
||||||
|
if nproviders == 0 {
|
||||||
|
return nil, E.New("missing subscription providers")
|
||||||
|
}
|
||||||
providers := make([]*subscriptionProvider, 0, len(options.SubscriptionOptions.Providers))
|
providers := make([]*subscriptionProvider, 0, len(options.SubscriptionOptions.Providers))
|
||||||
for _, p := range options.SubscriptionOptions.Providers {
|
for i, p := range options.SubscriptionOptions.Providers {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
|
tag string
|
||||||
exclude *regexp.Regexp
|
exclude *regexp.Regexp
|
||||||
include *regexp.Regexp
|
include *regexp.Regexp
|
||||||
)
|
)
|
||||||
|
if p.Tag != "" {
|
||||||
|
tag = p.Tag
|
||||||
|
} else {
|
||||||
|
tag = F.ToString(i)
|
||||||
|
}
|
||||||
|
if p.URL == "" {
|
||||||
|
return nil, E.New("missing URL for provider [", tag, "]")
|
||||||
|
}
|
||||||
if p.Exclude != "" {
|
if p.Exclude != "" {
|
||||||
exclude, err = regexp.Compile(p.Exclude)
|
exclude, err = regexp.Compile(p.Exclude)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -74,7 +86,12 @@ func NewSubscription(ctx context.Context, router adapter.Router, logger log.Cont
|
|||||||
Include: include,
|
Include: include,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
interval := time.Duration(options.SubscriptionOptions.Interval)
|
||||||
|
if interval < time.Minute {
|
||||||
|
interval = time.Minute
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx2, cancel := context.WithCancel(ctx)
|
||||||
return &Subscription{
|
return &Subscription{
|
||||||
myServiceAdapter: myServiceAdapter{
|
myServiceAdapter: myServiceAdapter{
|
||||||
router: router,
|
router: router,
|
||||||
@ -82,7 +99,7 @@ func NewSubscription(ctx context.Context, router adapter.Router, logger log.Cont
|
|||||||
logger: logger,
|
logger: logger,
|
||||||
tag: options.Tag,
|
tag: options.Tag,
|
||||||
},
|
},
|
||||||
interval: time.Duration(options.SubscriptionOptions.Interval),
|
interval: interval,
|
||||||
downloadDetour: options.SubscriptionOptions.DownloadDetour,
|
downloadDetour: options.SubscriptionOptions.DownloadDetour,
|
||||||
providers: providers,
|
providers: providers,
|
||||||
dialerOptions: options.SubscriptionOptions.DialerOptions,
|
dialerOptions: options.SubscriptionOptions.DialerOptions,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user