SearchUsers searches for users matching searchName. If searchName is a valid integer, the search matches by userId (exact match only). Otherwise it searches by username: an exact match returns a single result; all prefix matches are returned when there is no exact match. The username search is case
(searchName string)
| 21 | // result; all prefix matches are returned when there is no exact match. The |
| 22 | // username search is case-insensitive. |
| 23 | func SearchUsers(searchName string) []UserSearchResult { |
| 24 | if searchName == "" { |
| 25 | return nil |
| 26 | } |
| 27 | |
| 28 | // Numeric input: match by userId. |
| 29 | if uid, err := strconv.Atoi(searchName); err == nil && uid > 0 { |
| 30 | return searchByUserId(uid) |
| 31 | } |
| 32 | |
| 33 | return searchByUsername(searchName) |
| 34 | } |
| 35 | |
| 36 | func searchByUserId(uid int) []UserSearchResult { |
| 37 | type candidate struct { |
no test coverage detected