-
Notifications
You must be signed in to change notification settings - Fork 7
chore: use interfaces without indirects #29
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors interface usage by removing unnecessary pointer indirection for interface fields and variables, ensuring interfaces are passed and stored directly rather than as pointers.
- Updated
DOMAIN_GLOBALSandNewGlobalssignature to accept interfaces by value - Changed all call sites on
GLOB.DSP,GLOB.HSM,GLOB.CS,GLOB.RFTloc, and related globals to remove*dereferences - Adjusted test and application code across domain, API, and CLI layers for the new interface signatures
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/domain/globals.go | Changed interface fields to non-pointer types and updated NewGlobals signature |
| internal/domain/transitions.go | Removed pointer indirection on all GLOB interface method calls |
| internal/domain/transitions_test.go | Updated tests to call GLOB.DSP.Store... directly |
| internal/domain/power-status.go | Removed * dereferences for kvStore, hsmHandle, ccStore, distLocker, tloc |
| internal/domain/power-status_test.go | Updated credential and HSM data calls to remove pointer derefs |
| internal/domain/power-cap.go | Removed pointer indirection on GLOB.DSP, GLOB.HSM, GLOB.CS, GLOB.RFTloc |
| internal/domain/power-cap_test.go | Updated power-cap tests to use direct interface calls |
| internal/api/health.go | Removed pointer derefs for glb.DSP, glb.DistLock, glb.HSM, glb.CS, glb.RFTloc |
| internal/api/health_test.go | Updated health test setup to pass interfaces by value |
| cmd/power-control/main.go | Adjusted NewGlobals invocation and direct assignment to domainGlobals.RFTloc |
763af8e to
ebb4d78
Compare
|
@rainest Should we update, close, or merge this? |
|
We were holding off on merging this until the postgres work landed, it can be rebase and merged now I think. |
Do not dereference interface fields and vars, and pass struct pointers to functions that accept interfaces. Pointers to structs with the appropriate methods satisfy interfaces and are the standard means of passing interface arguments. Using pointers to interfaces requires weird type contortions. Signed-off-by: Travis Raines <[email protected]>
Signed-off-by: Travis Raines <[email protected]>
ebb4d78 to
1185c5f
Compare
|
Rebased, moved some changes to the new service cmd file. |
Summary and Scope
Do not dereference interface fields and vars, and pass struct pointers to functions that accept interfaces. Pointers to structs with the appropriate methods satisfy interfaces and are the standard means of passing interface arguments. Using pointers to interfaces requires weird type contortions.
This change is a backwards compatible code cleanliness change, and does not affect functionality.
Testing
Basically, if
go vetlikes it, it's good to go. Don't expect there's anything CI can find that the compiler can, but it's running anyway 🤷Issues and Related PRs
N/a, found working on something else.
Risks and Mitigations
Hopefully unlikely to cause conflicts, since these are largely simple function calls, but ideally this should be upstreamed.
Pull Request Checklist
Version number(s) incremented, if applicableCopyrights updatedCHANGELOG.md updatedcode only