Skip to content

Conversation

@rainest
Copy link
Contributor

@rainest rainest commented Jun 16, 2025

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 vet likes 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 applicable
  • Copyrights updated
  • License file intact
  • Target branch correct
  • CHANGELOG.md updated code only
  • Testing is appropriate and complete, if applicable

@alexlovelltroy alexlovelltroy requested a review from Copilot June 17, 2025 15:18
Copy link

Copilot AI left a 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_GLOBALS and NewGlobals signature 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

@rainest rainest force-pushed the rainest/interface-indirect branch from 763af8e to ebb4d78 Compare July 8, 2025 20:42
@alexlovelltroy
Copy link
Member

@rainest Should we update, close, or merge this?

@cjh1
Copy link
Member

cjh1 commented Aug 15, 2025

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]>
@rainest rainest force-pushed the rainest/interface-indirect branch from ebb4d78 to 1185c5f Compare August 18, 2025 19:32
@rainest rainest requested review from alexlovelltroy and cjh1 August 18, 2025 19:33
@rainest rainest enabled auto-merge (rebase) August 18, 2025 19:33
@rainest
Copy link
Contributor Author

rainest commented Aug 18, 2025

Rebased, moved some changes to the new service cmd file.

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.

5 participants