groupcache
groupcache copied to clipboard
Add validation to Set(peers ...string)
Check if each peers
input value to Set(peers ...string)
is a valid base URL as required and as noted in the func-level comments.
The prior version of Set()
did not include any validation of the input value(s) even though the func-level comments noted "Each peer value should be a valid base URL, for example 'http://example.net:8000'". This could lead to confusion when a cluster of peers cannot communicate. For example, if a user called Set("localhost:8080")
this may look correct but the host on which Set()
was called will not be able to communicate with the peer provided via the address localhost:8080
. This is compounded by the fact no error is returned, nor is anything logged, leading the user to believe the error is elsewhere besides with the inputted address.
To solve the above noted issue/confusion, Set()
was modified to check if each input value is a valid URL and return an error when an input value is invalid. This is done by checking if the input URL has the required scheme (http or https since groupcache only uses http based communication at this point) and if a host was provided. Modifying the Set()
func to return an error
should not break anything since you can ignore return values from funcs.
The lines of code within the Set()
func were reordered so that validation of input peer address could be done before setting of any pool data.