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

sign: Readability cleanups #41

Merged
merged 4 commits into from
Jun 26, 2024
Merged

sign: Readability cleanups #41

merged 4 commits into from
Jun 26, 2024

Conversation

DrJosh9000
Copy link
Contributor

@DrJosh9000 DrJosh9000 commented Jun 26, 2024

This PR addresses some gripes I had with the state of the sign package. Each commit has an explanation.

The only outward-facing change is to pass contexts idiomatically. Everything else is internal to how signing/verifying logging works or the tests.

It shouldn't be passed through an option pattern, since that causes it to be stored in a struct. It should be passed as the first arg. See https://pkg.go.dev/context.

This adds a ctx arg to Verify, which uses it, and Sign, which doesn't, but now looks weird without it.
"Handle errors before proceeding with the rest of your code" https://google.github.io/styleguide/go/decisions#indent-error-flow

Additionally, some `else` keywords are redundant (due to `return` in the `if` branch). Removing those avoids overly indenting the "main flow".
They seem to have drifted apart from the actual function calls. Error messages should identify the functions and arguments actually passed to aid with diagnosing test failures.
The distinction may seem trivial, but the "mock" approach causes confusion (even in the previous code: if mockLogger.passed { fail } ?) The test can be responsible for deciding if the logged output is valid, without hiding it inside a mock type.
@DrJosh9000 DrJosh9000 merged commit 3b5a1f4 into main Jun 26, 2024
1 check passed
@DrJosh9000 DrJosh9000 deleted the josh-cleanups branch June 26, 2024 02:23
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.

2 participants