AddUser adds a user to an inbound in the Xray core using the specified protocol and user data.
(Protocol string, inboundTag string, user map[string]any)
| 579 | |
| 580 | // AddUser adds a user to an inbound in the Xray core using the specified protocol and user data. |
| 581 | func (x *XrayAPI) AddUser(Protocol string, inboundTag string, user map[string]any) error { |
| 582 | userEmail, err := getRequiredUserString(user, "email") |
| 583 | if err != nil { |
| 584 | return err |
| 585 | } |
| 586 | |
| 587 | account, err := buildUserAccount(Protocol, user) |
| 588 | if err != nil { |
| 589 | return err |
| 590 | } |
| 591 | if account == nil { |
| 592 | return nil |
| 593 | } |
| 594 | |
| 595 | if x.HandlerServiceClient == nil { |
| 596 | return common.NewError("xray HandlerServiceClient is not initialized") |
| 597 | } |
| 598 | client := *x.HandlerServiceClient |
| 599 | |
| 600 | ctx, cancel := context.WithTimeout(context.Background(), handlerRPCTimeout) |
| 601 | defer cancel() |
| 602 | _, err = client.AlterInbound(ctx, &command.AlterInboundRequest{ |
| 603 | Tag: inboundTag, |
| 604 | Operation: serial.ToTypedMessage(&command.AddUserOperation{ |
| 605 | User: &protocol.User{ |
| 606 | Email: userEmail, |
| 607 | Account: account, |
| 608 | }, |
| 609 | }), |
| 610 | }) |
| 611 | return err |
| 612 | } |
| 613 | |
| 614 | // RemoveUser removes a user from an inbound in the Xray core by email. |
| 615 | func (x *XrayAPI) RemoveUser(inboundTag, email string) error { |
no test coverage detected