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

Refactor various utility functions into a consul/lib package #1666

Merged
merged 6 commits into from
Feb 2, 2016

Conversation

sean-
Copy link
Contributor

@sean- sean- commented Jan 31, 2016

Prevent the spread of duplicate code by breaking cyclic imports and consolidating various util functions into a consul/lib package.

sean- added 2 commits January 29, 2016 16:57
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 {
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@slackpad
Copy link
Contributor

slackpad commented Feb 1, 2016

Noted a couple things I had questions about, otherwise looks good!

@slackpad
Copy link
Contributor

slackpad commented Feb 2, 2016

LGTM

@slackpad
Copy link
Contributor

slackpad commented Feb 2, 2016

LGTM for reals

sean- added a commit that referenced this pull request Feb 2, 2016
Refactor various utility functions into a consul/lib package
@sean- sean- merged commit eb27a02 into master Feb 2, 2016
@sean- sean- deleted the f-consul-lib branch February 2, 2016 07:10
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