-
Notifications
You must be signed in to change notification settings - Fork 1
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
Validate against forbidden fields #232
Conversation
} | ||
|
||
for key, _ := range pgConf { | ||
if key == "listen_addresses" { |
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.
Can you please define a list of forbidden pg parameters on top of this file and instead of having multiple if clauses to just have one? I would also consider create a new go file to separate the concerns and make it a bit more readable
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.
I agree, having a map of forbidden keys would be more readable. You can use the maps key for the field name, so you can efficiently do checks. Then use the value of the map to store the specifics of the error.
It would also be easier to extend or change in the future.
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.
The errors seems to be almost the same, only the name is added to a field. I would still go with just a list.
} | ||
|
||
for key, _ := range pgConf { | ||
if key == "listen_addresses" { |
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.
I agree, having a map of forbidden keys would be more readable. You can use the maps key for the field name, so you can efficiently do checks. Then use the value of the map to store the specifics of the error.
It would also be easier to extend or change in the future.
} | ||
} | ||
|
||
blocklist := map[string]string{ |
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.
why did you create a map if the values are empty? Please change to a list and move it outside the function at the top of the file. Our code is already very confusing, lets not make it a pain to read.
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.
The idea for the map is that we don't have nested loops, so I would keep it as such.
But I agree to move it to the top.
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.
You meant that there's no good way to search in the list? I forgot how bad go is in that regard... but there are packages that help with finding an object in the list... I would still have gone with the list... it hearts my eyes to see empty strings there, it feels like they will be filled during a for loop....
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.
finding an element in array is the same operation in each language, finding key in map is O(1) . O(n^2) You suggest would hurt my eyes ;p
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.
LGTM
Summary
Checklist
bug
,enhancement
,documentation
,change
,breaking
,dependency
as they show up in the changelog