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.
(id interface{})
| 112 | // id must be a string for username lookup or a uint for id lookup. If id |
| 113 | // is neither, a ErrInvalidDataType will be returned. |
| 114 | func (s *Storage) Delete(id interface{}) error { |
| 115 | switch id := id.(type) { |
| 116 | case string: |
| 117 | user, err := s.back.GetBy(id) |
| 118 | if err != nil { |
| 119 | return err |
| 120 | } |
| 121 | if s.IsUniqueAdmin(user) { |
| 122 | return fberrors.ErrRootUserDeletion |
| 123 | } |
| 124 | |
| 125 | return s.back.DeleteByUsername(id) |
| 126 | case uint: |
| 127 | user, err := s.back.GetBy(id) |
| 128 | if err != nil { |
| 129 | return err |
| 130 | } |
| 131 | if s.IsUniqueAdmin(user) { |
| 132 | return fberrors.ErrRootUserDeletion |
| 133 | } |
| 134 | |
| 135 | return s.back.DeleteByID(id) |
| 136 | default: |
| 137 | return fberrors.ErrInvalidDataType |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | // LastUpdate gets the timestamp for the last update of an user. |
| 142 | func (s *Storage) LastUpdate(id uint) int64 { |
nothing calls this directly
no test coverage detected