-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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 various utility functions into a consul/lib package #1666
Conversation
Consolidate code duplication and tests into a single lib package. Most of these functions were from various **/util.go functions that couldn't be imported due to cyclic imports. The consul/lib package is intended to be a terminal node in an import DAG and a place to stash various consul-only helper functions. Pulled in hashicorp/go-uuid instead of consolidating UUID access.
Required for jitter calcs. This could be done in consul/agent, but this makes it clear it is done only once process-wide.
@@ -41,7 +42,9 @@ func (p *PreparedQuery) Apply(args *structs.PreparedQueryRequest, reply *string) | |||
// to collide since this isn't inside a write transaction. | |||
state := p.srv.fsm.State() | |||
for { | |||
args.Query.ID = generateUUID() | |||
if args.Query.ID, err = uuid.GenerateUUID(); err != nil { |
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.
Which err
variable is in scope at this point? I'd expect a compile error here.
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.
It's using the function's return parameter, err
. Upon entry into Apply
, err
is zero initialized and visible for the entire scope of Apply
.
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.
Ah gotcha. Missed that one was named.
Noted a couple things I had questions about, otherwise looks good! |
LGTM |
exported function.
LGTM for reals |
Refactor various utility functions into a consul/lib package
Prevent the spread of duplicate code by breaking cyclic imports and consolidating various util functions into a consul/lib package.