github.com/xraypb/Xray-core@v1.8.1/main/commands/all/api/inbounds_remove.go (about) 1 package api 2 3 import ( 4 "fmt" 5 6 handlerService "github.com/xraypb/Xray-core/app/proxyman/command" 7 "github.com/xraypb/Xray-core/infra/conf/serial" 8 "github.com/xraypb/Xray-core/main/commands/base" 9 ) 10 11 var cmdRemoveInbounds = &base.Command{ 12 CustomFlags: true, 13 UsageLine: "{{.Exec}} api rmi [--server=127.0.0.1:8080] <json_file|tag> [json_file] [tag]...", 14 Short: "Remove inbounds", 15 Long: ` 16 Remove inbounds from Xray. 17 Arguments: 18 -s, -server 19 The API server address. Default 127.0.0.1:8080 20 -t, -timeout 21 Timeout seconds to call API. Default 3 22 Example: 23 {{.Exec}} {{.LongName}} --server=127.0.0.1:8080 c1.json "tag name" 24 `, 25 Run: executeRemoveInbounds, 26 } 27 28 func executeRemoveInbounds(cmd *base.Command, args []string) { 29 setSharedFlags(cmd) 30 cmd.Flag.Parse(args) 31 unnamedArgs := cmd.Flag.Args() 32 if len(unnamedArgs) == 0 { 33 fmt.Println("reading from stdin:") 34 unnamedArgs = []string{"stdin:"} 35 } 36 37 tags := make([]string, 0) 38 for _, arg := range unnamedArgs { 39 if r, err := loadArg(arg); err == nil { 40 conf, err := serial.DecodeJSONConfig(r) 41 if err != nil { 42 base.Fatalf("failed to decode %s: %s", arg, err) 43 } 44 ins := conf.InboundConfigs 45 for _, i := range ins { 46 tags = append(tags, i.Tag) 47 } 48 } else { 49 // take request as tag 50 tags = append(tags, arg) 51 } 52 } 53 54 if len(tags) == 0 { 55 base.Fatalf("no inbound to remove") 56 } 57 fmt.Println("removing inbounds:", tags) 58 59 conn, ctx, close := dialAPIServer() 60 defer close() 61 62 client := handlerService.NewHandlerServiceClient(conn) 63 for _, tag := range tags { 64 fmt.Println("removing:", tag) 65 r := &handlerService.RemoveInboundRequest{ 66 Tag: tag, 67 } 68 resp, err := client.RemoveInbound(ctx, r) 69 if err != nil { 70 base.Fatalf("failed to remove inbound: %s", err) 71 } 72 showJSONResponse(resp) 73 } 74 }