Skip to content

Commit

Permalink
misc style tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bradfitz committed Nov 8, 2014
1 parent c2ad34c commit 19812ca
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion memcache/memcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var (
)

// DefaultTimeout is the default socket read/write timeout.
const DefaultTimeout = time.Duration(100) * time.Millisecond
const DefaultTimeout = 100 * time.Millisecond

const (
buffered = 8 // arbitrary buffered channel size, for readability
Expand Down
19 changes: 10 additions & 9 deletions memcache/selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ import (
// ServerSelector is the interface that selects a memcache server
// as a function of the item's key.
//
// All ServerSelector implementations must be threadsafe.
// All ServerSelector implementations must be safe for concurrent use
// by multiple goroutines.
type ServerSelector interface {
// PickServer returns the server address that a given item
// should be shared onto.
Expand All @@ -36,12 +37,12 @@ type ServerSelector interface {

// ServerList is a simple ServerSelector. Its zero value is usable.
type ServerList struct {
lk sync.RWMutex
mu sync.RWMutex
addrs []net.Addr
}

// SetServers changes a ServerList's set of servers at runtime and is
// threadsafe.
// safe for concurrent use by multiple goroutines.
//
// Each server is given equal weight. A server is given more weight
// if it's listed multiple times.
Expand All @@ -67,16 +68,16 @@ func (ss *ServerList) SetServers(servers ...string) error {
}
}

ss.lk.Lock()
defer ss.lk.Unlock()
ss.mu.Lock()
defer ss.mu.Unlock()
ss.addrs = naddr
return nil
}

// Each iterates over each server calling the given function
func (ss *ServerList) Each(f func(net.Addr) error) error {
ss.lk.RLock()
defer ss.lk.RUnlock()
ss.mu.RLock()
defer ss.mu.RUnlock()
for _, a := range ss.addrs {
if err := f(a); nil != err {
return err
Expand All @@ -86,8 +87,8 @@ func (ss *ServerList) Each(f func(net.Addr) error) error {
}

func (ss *ServerList) PickServer(key string) (net.Addr, error) {
ss.lk.RLock()
defer ss.lk.RUnlock()
ss.mu.RLock()
defer ss.mu.RUnlock()
if len(ss.addrs) == 0 {
return nil, ErrNoServers
}
Expand Down

0 comments on commit 19812ca

Please sign in to comment.