AddOutbound adds a new outbound configuration to the Xray core via gRPC.
(outbound []byte)
| 173 | |
| 174 | // AddOutbound adds a new outbound configuration to the Xray core via gRPC. |
| 175 | func (x *XrayAPI) AddOutbound(outbound []byte) error { |
| 176 | if x.HandlerServiceClient == nil { |
| 177 | return common.NewError("xray HandlerServiceClient is not initialized") |
| 178 | } |
| 179 | client := *x.HandlerServiceClient |
| 180 | |
| 181 | conf := new(conf.OutboundDetourConfig) |
| 182 | if err := json.Unmarshal(outbound, conf); err != nil { |
| 183 | logger.Debug("Failed to unmarshal outbound:", err) |
| 184 | return err |
| 185 | } |
| 186 | config, err := conf.Build() |
| 187 | if err != nil { |
| 188 | logger.Debug("Failed to build outbound detour:", err) |
| 189 | return err |
| 190 | } |
| 191 | |
| 192 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) |
| 193 | defer cancel() |
| 194 | |
| 195 | _, err = client.AddOutbound(ctx, &command.AddOutboundRequest{Outbound: config}) |
| 196 | return err |
| 197 | } |
| 198 | |
| 199 | // DelOutbound removes an outbound configuration from the Xray core by tag. |
| 200 | func (x *XrayAPI) DelOutbound(tag string) error { |