Lots of duplicated code in proxy.go
Closed this issue · 2 comments
Username404-59 commented
The following snippet:
proxy.Config.RLock()
defer proxy.Config.RUnlock()
appears around 12 times
Edit: I put the wrong label, this is not a bug
4kills commented
So what do you propose?
The snippet as is can not be extracted to a function/method. This is because the defer makes the following statment execute once the function exits.
So every snippet of this:
proxy.Config.RLock()
defer proxy.Config.RUnlock()
is actually something like for example this:
proxy.Config.RLock()
// some code
if someVariable {
proxy.Config.RUnlock()
return
}
// some more code
proxy.Config.RUnlock()
The only way I see how this code snippet could be removed is by creating a middleware method/function similar to how the http
packet operates. However, I don't think removing a snippet like this would warrant such a major refactor since it would not add much benefit. Locking and immediately deferring to unlock a ReadLock is pretty much standard procedure.