mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-10-01 20:15:45 +00:00
Add api command
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/sagernet/sing-box/daemon"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var commandAPIGroupSelect = &cobra.Command{
|
||||
Use: "select <group> <outbound>",
|
||||
Short: "Select an outbound in a group",
|
||||
Args: cobra.ExactArgs(2),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runAPIGroupSelect(args[0], args[1])
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
commandAPIGroup.AddCommand(commandAPIGroupSelect)
|
||||
}
|
||||
|
||||
func runAPIGroupSelect(groupTag string, outboundTag string) error {
|
||||
clientConn, client, err := createAPIClient()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer clientConn.Close()
|
||||
_, err = client.SelectOutbound(globalCtx, &daemon.SelectOutboundRequest{
|
||||
GroupTag: groupTag,
|
||||
OutboundTag: outboundTag,
|
||||
})
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user