MCPcopy
hub / github.com/MHSanaei/3x-ui / AddUser

Method AddUser

internal/xray/api.go:581–612  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

579
580// AddUser adds a user to an inbound in the Xray core using the specified protocol and user data.
581func (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.
615func (x *XrayAPI) RemoveUser(inboundTag, email string) error {

Callers 1

Calls 3

NewErrorFunction · 0.92
getRequiredUserStringFunction · 0.85
buildUserAccountFunction · 0.85

Tested by

no test coverage detected