Add command to fetch a URL

This commit is contained in:
世界
2023-03-18 21:02:29 +08:00
parent e5f3bb6344
commit 99b2ab5526
3 changed files with 135 additions and 10 deletions

View File

@@ -4,14 +4,16 @@ import (
"context"
box "github.com/sagernet/sing-box"
"github.com/sagernet/sing-box/option"
E "github.com/sagernet/sing/common/exceptions"
N "github.com/sagernet/sing/common/network"
"github.com/spf13/cobra"
)
var commandTools = &cobra.Command{
Use: "tools",
Short: "experimental tools",
Short: "Experimental tools",
}
func init() {
@@ -23,6 +25,10 @@ func createPreStartedClient() (*box.Box, error) {
if err != nil {
return nil, err
}
if options.Log == nil {
options.Log = &option.LogOptions{}
}
options.Log.Disabled = true
instance, err := box.New(context.Background(), options, nil)
if err != nil {
return nil, E.Cause(err, "create service")
@@ -33,3 +39,19 @@ func createPreStartedClient() (*box.Box, error) {
}
return instance, nil
}
func createDialer(instance *box.Box, network string, outboundTag string) (N.Dialer, error) {
if outboundTag == "" {
outbound := instance.Router().DefaultOutbound(network)
if outbound == nil {
return nil, E.New("missing default outbound")
}
return outbound, nil
} else {
outbound, loaded := instance.Router().Outbound(outboundTag)
if !loaded {
return nil, E.New("outbound not found: ", outboundTag)
}
return outbound, nil
}
}