|
|
|
@ -92,17 +92,25 @@ func (s *Storage) Save(user *User) error {
|
|
|
|
|
// Delete allows you to delete a user by its name or username. The provided
|
|
|
|
|
// id must be a string for username lookup or a uint for id lookup. If id
|
|
|
|
|
// is neither, a ErrInvalidDataType will be returned.
|
|
|
|
|
func (s *Storage) Delete(id interface{}) (err error) {
|
|
|
|
|
func (s *Storage) Delete(id interface{}) error {
|
|
|
|
|
switch id := id.(type) {
|
|
|
|
|
case string:
|
|
|
|
|
err = s.back.DeleteByUsername(id)
|
|
|
|
|
user, err := s.back.GetBy(id)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
if user.ID == 1 {
|
|
|
|
|
return errors.ErrRootUserDeletion
|
|
|
|
|
}
|
|
|
|
|
return s.back.DeleteByUsername(id)
|
|
|
|
|
case uint:
|
|
|
|
|
err = s.back.DeleteByID(id)
|
|
|
|
|
if id == 1 {
|
|
|
|
|
return errors.ErrRootUserDeletion
|
|
|
|
|
}
|
|
|
|
|
return s.back.DeleteByID(id)
|
|
|
|
|
default:
|
|
|
|
|
err = errors.ErrInvalidDataType
|
|
|
|
|
return errors.ErrInvalidDataType
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// LastUpdate gets the timestamp for the last update of an user.
|
|
|
|
|