nomad icon indicating copy to clipboard operation
nomad copied to clipboard

tools: structs method generation

Open tgross opened this issue 4 years ago • 4 comments

Developers are required to implement methods like Copy, Equals, Diff, and Merge for many of the types in the structs package, and this is both time-consuming and error prone, having resulted in several correctness bugs from failing to copy objects retrieved from go-memdb or failing to compare objects during plans.

This changeset introduces a prototype tool to use with go:generate directives that can generate methods automatically for our developers. Future changesets will include documentation for developers and porting the existing methods to use this tool. We'll continue to debug and refine the tool as we go.

(Co-authored with @DerekStrickland )

tgross avatar Jun 25 '21 19:06 tgross

@schmichael @tgross I'll take a stab at a README, similar to what I am doing in this jobspec update PR https://github.com/hashicorp/nomad/pull/10819.

Also, I had some readability/maintainability refactorings in another branch that didn't land in time for Friday. I'll take a stab at rebasing it off of this + adding comments and then see if we want to merge.

DerekStrickland avatar Jun 28 '21 09:06 DerekStrickland

@tgross @schmichael Here's the other branch. Let me know if you'd prefer a PR targeting this one. https://github.com/hashicorp/nomad/tree/generate-structs-refactor

DerekStrickland avatar Jun 28 '21 16:06 DerekStrickland

Let me know if you'd prefer a PR targeting this one.

You can probably just drop commits onto this PR if you want, but I'd strongly recommend splitting the file rename refactor from any other refactors so that folks can review them separately. Ex. right now https://github.com/hashicorp/nomad/compare/generate-structs...generate-structs-refactor just show the whole file getting replaced.

tgross avatar Jun 28 '21 17:06 tgross

CLA assistant check
All committers have signed the CLA.

hashicorp-cla avatar Mar 12 '22 17:03 hashicorp-cla