Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Simplify UnmarshalJSON with Dedicated Handlers #695

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

haitwang-cloud
Copy link

@haitwang-cloud haitwang-cloud commented May 6, 2024

This PR refactors the UnmarshalJSON method for ReplicatedDevices to improve code clarity and structure. Key changes include:

  • Modularization: Created separate handlers (handleStringInput, handleNumericInput, handleListInput) for different input types, enhancing readability and simplifying future maintenance.

  • Robust Error Handling: Enhanced the error handling in handleListInput to allow processing of list elements independently.

  • Code Refactoring: Eliminated redundancy by centralizing error checking logic.

  • Generics Readiness: Prepared handleNumericInput for future adaptation to Go's generics (once available).

@haitwang-cloud
Copy link
Author

@klueska PTAL

@haitwang-cloud
Copy link
Author

haitwang-cloud commented May 7, 2024

Upon reviewing, I identified a bug in the previous submission that resulted in the failure of two existing unit test functions. To address this, I've removed the switch statement, which was causing the issue.

Here are the current unit test results:

(base) ➜  v1 git:(main) ✗ go test ./...                          
ok      github.com/NVIDIA/k8s-device-plugin/api/config/v1       0.634s

@haitwang-cloud haitwang-cloud changed the title 🎨Optimize UnmarshalJSON in ReplicatedDevices structure [Refactor] Simplify UnmarshalJSON with Dedicated Handlers May 7, 2024
@haitwang-cloud
Copy link
Author

Ping @klueska

@haitwang-cloud
Copy link
Author

Ping @elezar

Signed-off-by: haitwang-cloud <haitao_wht@outlook.com>
Signed-off-by: haitwang-cloud <haitao_wht@outlook.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant