groupcache
groupcache copied to clipboard
http pool basePath getter and/or setter?
I'm building a server that uses groupcache, and I would like to be able to conveniently wrap the http pool's handler inside a mux (specifically to add a monitoring status call on the server).
I simply thought of adding a handler func that forwards everything under /_groupcache/ to groupcache's handler. But this will fail if ever the hard coded base path will change.
So I thought of adding at least a getter, if not a setter for the base path. I understand the consistency problem with adding a setter. Will a pull request for GetBasePath() and/or SetBasePath() be accepted?
Can't you just wrap the handler with http.StripPrefix/
The way I understand it no, but I'd gladly stand corrected. Groupcache handles everything by default, and panics if that doesn't begin with its basePath (/_groupcache), that is not configurable (and has the comment: // TODO: make this configurable?
), is not exported and doesn't have a getter.
I just hard coded that into my code, but you know, it feels wrong :)
I wouldn't be opposed to adding these methods:
BasePath() string
SetBasePath(p string)
Alright, I'll gladly do this and add do a PR.
@nf wouldn't it be a tad more elegant, instead of adding a setter to simply add in http.go (67):
func NewHTTPPool(self, basePath string) *HTTPPool {
...
I mean, you wouldn't change the basePath during serving.
Yep, probably.
Do that :-)
I just hit this, I'd even be happy if defaultBasePath was DefaultBasePath so that muxer registration wasn't by a copy of the constant.