mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-05-14 08:52:47 +03:00
32 lines
853 B
Go
32 lines
853 B
Go
package parser
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/sagernet/sing-box/option"
|
|
"github.com/sagernet/sing-box/parser/clash"
|
|
"github.com/sagernet/sing-box/parser/raw"
|
|
"github.com/sagernet/sing-box/parser/singbox"
|
|
"github.com/sagernet/sing-box/parser/sip008"
|
|
E "github.com/sagernet/sing/common/exceptions"
|
|
)
|
|
|
|
var subscriptionParsers = []func(ctx context.Context, content string) ([]option.Outbound, error){
|
|
singbox.ParseBoxSubscription,
|
|
clash.ParseClashSubscription,
|
|
sip008.ParseSIP008Subscription,
|
|
raw.ParseRawSubscription,
|
|
}
|
|
|
|
func ParseSubscription(ctx context.Context, content string) ([]option.Outbound, error) {
|
|
var pErr error
|
|
for _, parser := range subscriptionParsers {
|
|
servers, err := parser(ctx, content)
|
|
if len(servers) > 0 {
|
|
return servers, nil
|
|
}
|
|
pErr = E.Errors(pErr, err)
|
|
}
|
|
return nil, E.Cause(pErr, "no servers found")
|
|
}
|