News for hackers. Stuff that matters.
Re:Let's Create a Simple Load Balancer with Go by arberavdullahu on Sunday November 10, 2019 @06:56AM (#21497635)
I found it more convenient to keep the field unnamed when using mutex in a struct. So in the example that would be

type Backend struct {

  URL          *url.URL

  Alive        bool

  sync.RWMutex

  ReverseProxy *httputil.ReverseProxy

}
Re:Let's Create a Simple Load Balancer with Go by mutatio on Sunday November 10, 2019 @08:15AM (#21497829)
The problem with that is that the methods for `sync.RWMutex` spill into `Backend`.
Re:Let's Create a Simple Load Balancer with Go by thegeekpirate on Sunday November 10, 2019 @08:35AM (#21497898)
That isn't a problem—in fact, that's the entire point of arberavdullahu's suggestion.
Re:Let's Create a Simple Load Balancer with Go by fiveturns on Sunday November 10, 2019 @10:59AM (#21498457)
Still seems like a problem to me. It breaks encapsulation.

The mutex is only used inside of SetAlive() and isAlive(), they're the only things this need to handle locking and unlocking. You don't want anything external to that calling the methods on RWMutex.

Re:Let's Create a Simple Load Balancer with Go by thegeekpirate on Sunday November 10, 2019 @11:31AM (#21498651)
Oh of course, if you're not using it then don't expose it.

I haven't read the code so I can't verify if that's the case here, but I read OPs post as being worried about method clobbering (which is really a non-issue, if the popularity of embedding mutexes shows us anything).