MCPcopy Create free account
hub / github.com/gogs/gogs / GetByID

Method GetByID

internal/database/users.go:732–742  ·  view source on GitHub ↗

GetByID returns the user with given ID. It returns ErrUserNotExist when not found.

(ctx context.Context, id int64)

Source from the content-addressed store, hash-verified

730// GetByID returns the user with given ID. It returns ErrUserNotExist when not
731// found.
732func (s *UsersStore) GetByID(ctx context.Context, id int64) (*User, error) {
733 user := new(User)
734 err := s.db.WithContext(ctx).Where("id = ?", id).First(user).Error
735 if err != nil {
736 if errors.Is(err, gorm.ErrRecordNotFound) {
737 return nil, ErrUserNotExist{args: errutil.Args{"userID": id}}
738 }
739 return nil, err
740 }
741 return user, nil
742}
743
744// GetByUsername returns the user with given username. It returns
745// ErrUserNotExist when not found.

Callers 4

ChangeUsernameMethod · 0.95
DeleteByIDMethod · 0.95
ListEmailsMethod · 0.95
MarkEmailPrimaryMethod · 0.95

Calls 1

WhereMethod · 0.80

Tested by

no test coverage detected