Conversation
The `Select` functions are removed as they lead to less efficient code
There was a problem hiding this comment.
Pull request overview
This PR refactors the client interfaces for Users, Groups, and API Tokens to improve code efficiency and consistency. The changes remove inefficient selection methods in favor of standard map operations and add support for Go 1.23+ iterators.
Changes:
- Removed
SelectXfunctions (SelectUser,SelectName) which led to O(n) lookup performance for each call - Renamed
FormatArrayandFormatMapto more idiomaticAsArrayandAsMap - Added
Iter()methods that returniter.Seq[T]for efficient iteration over raw data structures
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| proxmox/config__user.go | Updated RawUsersInfo interface: removed SelectUser, renamed formatting methods, added Iter() |
| proxmox/config__group.go | Updated RawGroups interface: removed SelectName, renamed formatting methods, added Iter() |
| proxmox/config__apiToken.go | Updated RawApiTokens interface: removed SelectName, renamed formatting methods, added Iter() |
| proxmox/config__user_test.go | Refactored tests: renamed test functions, removed SelectUser tests, added comprehensive iterator tests |
| proxmox/config__group_test.go | Refactored tests: renamed test functions, removed SelectName tests, added iterator tests, fixed test data (members array) |
| proxmox/config__apiToken_test.go | Refactored tests: renamed test functions, removed SelectName tests, added comprehensive iterator tests |
| test/api/User/list_user_test.go | Updated to use AsMap() instead of SelectUser() for efficient lookups |
| test/api/Group/list_group_test.go | Updated to use AsMap()[key] instead of SelectName() |
| test/api/Group/create_group_test.go | Updated to use AsMap()[key] instead of SelectName() |
| test/api/ApiToken/list_token_test.go | Updated to use AsMap() instead of FormatMap() |
| main.go | Updated to use AsArray() instead of FormatArray() |
| cli/command/list/list-users.go | Updated to use AsArray() instead of FormatArray() |
| cli/command/list/list-tokens.go | Updated to use AsArray() instead of FormatArray() |
| cli/command/list/list-groups.go | Updated to use AsArray() instead of FormatArray() |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| func Test_RawGroups_FormatArray(t *testing.T) { | ||
| tests := []struct { | ||
| func test_RawGroups_Array_Data() []struct { |
There was a problem hiding this comment.
The function name should be test_rawGroups_Array_Data (lowercase 'r') to maintain consistency with the naming convention used in similar helper functions in config__user_test.go (test_rawUsersInfo_Array_Data) and config__apiToken_test.go (test_rawApiTokens_Array_Data).
| func test_RawGroups_Array_Data() []struct { | |
| func test_rawGroups_Array_Data() []struct { |
SelectXfunctions as they lead to inefficient code.FormatArrayandFormatMaptoAsArrayandAsMap.