-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support sing-box config as subscription
- Loading branch information
1 parent
ce53488
commit d0cefb3
Showing
6 changed files
with
42 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,24 @@ | ||
package libsubscription | ||
|
||
import ( | ||
"github.com/sagernet/sing-box/log" | ||
E "github.com/sagernet/sing/common/exceptions" | ||
) | ||
|
||
var subscriptionParsers = []func(string) ([]Server, error){ | ||
ParseBoxSubscription, | ||
ParseClashSubscription, | ||
ParseSIP008Subscription, | ||
ParseRawSubscription, | ||
} | ||
|
||
func ParseSubscription(content string) ([]Server, error) { | ||
var pErr error | ||
for _, parser := range subscriptionParsers { | ||
servers, err := parser(content) | ||
if len(servers) > 0 { | ||
return servers, nil | ||
} | ||
log.Trace("parse subscription failed: ", err) | ||
pErr = E.Errors(pErr, err) | ||
} | ||
return nil, E.New("no servers found") | ||
return nil, E.Cause(pErr, "no servers found") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package libsubscription | ||
|
||
import ( | ||
C "github.com/sagernet/sing-box/constant" | ||
"github.com/sagernet/sing-box/option" | ||
"github.com/sagernet/sing/common" | ||
E "github.com/sagernet/sing/common/exceptions" | ||
) | ||
|
||
func ParseBoxSubscription(content string) ([]Server, error) { | ||
var options option.Options | ||
err := options.UnmarshalJSON([]byte(content)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if len(options.Outbounds) == 0 { | ||
return nil, E.New("no servers found") | ||
} | ||
return common.Map(options.Outbounds, func(it option.Outbound) Server { | ||
return Server{ | ||
Name: it.Tag, | ||
Outbounds: []option.Outbound{it}, | ||
} | ||
}), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters