Skip to content

Commit 6d48c78

Browse files
refactor: streamline input handling in MetadataLookup method
- Updated the MetadataLookup method to utilize a switch statement for improved clarity in determining the lookup strategy based on input format. - Simplified the logic for handling canonical, email, and username lookups, enhancing code readability and maintainability. Jira Ticket: https://linuxfoundation.atlassian.net/browse/LFXV2-499 Generated with [Cursor](https://cursor.com/) Signed-off-by: Mauricio Zanetti Salomao <mauriciozanetti86@gmail.com>
1 parent 72dcf4a commit 6d48c78

File tree

1 file changed

+4
-3
lines changed
  • internal/infrastructure/mock

1 file changed

+4
-3
lines changed

internal/infrastructure/mock/user.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,21 +229,22 @@ func (u *userWriter) MetadataLookup(ctx context.Context, input string) (*model.U
229229
}
230230

231231
// Determine lookup strategy based on input format
232-
if strings.Contains(input, "|") {
232+
switch {
233+
case strings.Contains(input, "|"):
233234
// Input contains "|", use as sub for canonical lookup
234235
user.Sub = input
235236
user.UserID = input
236237
user.Username = ""
237238
user.PrimaryEmail = ""
238239
slog.InfoContext(ctx, "mock: canonical lookup strategy", "sub", input)
239-
} else if strings.Contains(input, "@") {
240+
case strings.Contains(input, "@"):
240241
// Input looks like an email, use for email search
241242
user.PrimaryEmail = strings.ToLower(input) // Normalize email to lowercase
242243
user.Sub = ""
243244
user.UserID = ""
244245
user.Username = ""
245246
slog.InfoContext(ctx, "mock: email search strategy", "email", user.PrimaryEmail)
246-
} else {
247+
default:
247248
// Input doesn't contain "|" or "@", use for username search
248249
user.Username = input
249250
user.Sub = ""

0 commit comments

Comments
 (0)