github.com/xmplusdev/xray-core@v1.8.10/main/commands/all/api/rules_remove.go (about) 1 package api 2 3 import ( 4 "fmt" 5 6 routerService "github.com/xmplusdev/xray-core/app/router/command" 7 "github.com/xmplusdev/xray-core/main/commands/base" 8 ) 9 10 var cmdRemoveRules = &base.Command{ 11 CustomFlags: true, 12 UsageLine: "{{.Exec}} api rmrules [--server=127.0.0.1:8080] ruleTag1 ruleTag2...", 13 Short: "Remove routing rules by ruleTag", 14 Long: ` 15 Remove routing rules by ruleTag from Xray. 16 Arguments: 17 -s, -server 18 The API server address. Default 127.0.0.1:8080 19 -t, -timeout 20 Timeout seconds to call API. Default 3 21 Example: 22 {{.Exec}} {{.LongName}} --server=127.0.0.1:8080 ruleTag1 ruleTag2 23 `, 24 Run: executeRemoveRules, 25 } 26 27 func executeRemoveRules(cmd *base.Command, args []string) { 28 setSharedFlags(cmd) 29 cmd.Flag.Parse(args) 30 ruleTags := cmd.Flag.Args() 31 if len(ruleTags) == 0 { 32 fmt.Println("reading from stdin:") 33 ruleTags = []string{"stdin:"} 34 } 35 conn, ctx, close := dialAPIServer() 36 defer close() 37 38 client := routerService.NewRoutingServiceClient(conn) 39 40 if len(ruleTags) == 0 { 41 base.Fatalf("no valid ruleTag input") 42 } 43 for _, tag := range ruleTags { 44 45 rr := &routerService.RemoveRuleRequest{ 46 RuleTag: tag, 47 } 48 resp, err := client.RemoveRule(ctx, rr) 49 if err != nil { 50 base.Fatalf("failed to perform RemoveRule: %s", err) 51 } 52 showJSONResponse(resp) 53 } 54 55 }