Skip to content

Make code more idiomatic#55

Open
stephenwithav wants to merge 8 commits into
CrunchyData:masterfrom
stephenwithav:refactor-func-main-and-util-branch
Open

Make code more idiomatic#55
stephenwithav wants to merge 8 commits into
CrunchyData:masterfrom
stephenwithav:refactor-func-main-and-util-branch

Conversation

@stephenwithav

Copy link
Copy Markdown

This and #54 both branch from master.

They can be merged in either order, but some rebasing may need to occur between merges.

This branch refactors redundant code and makes better use of the of the databas/sql package.

cmd.Run returns an error value, which is nil when no error occurs,
so nil-checking the ossible error in execute wastes cycles.
We may need findConfigOrFail to check more than strings in the
future.  This works until we reach that point.

@abrightwell abrightwell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, these are all good changes. Some minor comments that I'd prefer to be addressed before approval.

Comment thread main.go
os.Exit(1)
}
findConfigOrFail(Primary, "Must specify a primary PostgreSQL instance.", 17)
findConfigOrFail(Replica, "Must specify a replica PostgreSQL instance for failover.", 18)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactoring to a function seems good. But, I'd prefer that we not use arbitrary exit codes for this kind of failure. I believe that the original implementation of os.Exit(1) was sufficient for this purpose.

Comment thread util/replica.go
rows, err := conn.Query("SELECT current_setting('server_version_num')")

if err != nil {
version := 0

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the purpose of being explicit about types related to queries, I'd prefer that it stay as var version int.

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