Skip to content
This repository was archived by the owner on Nov 26, 2018. It is now read-only.

Commit 5396e02

Browse files
mvdanyml
authored andcommitted
Don't pass structs using locks by value
If passed by value, the locks lose all purpose. Reported by go vet.
1 parent 59761e0 commit 5396e02

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

common/mock.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type MockSocket struct {
2626
Receiver chan string
2727
}
2828

29-
func (sock MockSocket) Write(data []byte) (int, error) {
29+
func (sock *MockSocket) Write(data []byte) (int, error) {
3030
glog.V(3).Infoln("[Debug]: Starting MockSocket.Write of:", string(data))
3131
if sock.Counter != nil {
3232
sock.Counter <- true
@@ -38,14 +38,14 @@ func (sock MockSocket) Write(data []byte) (int, error) {
3838
return len(data), nil
3939
}
4040

41-
func (sock MockSocket) Read(into []byte) (int, error) {
41+
func (sock *MockSocket) Read(into []byte) (int, error) {
4242
sock.RLock()
4343
defer sock.RUnlock()
4444
time.Sleep(time.Second) // Prevent busy loop
4545
return 0, nil
4646
}
4747

48-
func (sock MockSocket) Close() error {
48+
func (sock *MockSocket) Close() error {
4949
if sock.Receiver != nil {
5050
close(sock.Receiver)
5151
}

network/irc/irc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type chatBotStats struct {
4040
m map[string]*expvar.Map
4141
}
4242

43-
func (s chatBotStats) GetOrCreate(identifier string) (*expvar.Map, bool) {
43+
func (s *chatBotStats) GetOrCreate(identifier string) (*expvar.Map, bool) {
4444
s.RLock()
4545
chatbotStats, ok := s.m[identifier]
4646
s.RUnlock()

network/irc/irc_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func TestFlood(t *testing.T) {
176176
pingResponse: make(chan struct{}, 10), // HACK: This is to avoid the current deadlock
177177
sendQueue: make(chan []byte, 256),
178178
}
179-
chatbot.init(mockSocket)
179+
chatbot.init(&mockSocket)
180180

181181
startTime := time.Now()
182182

@@ -224,7 +224,7 @@ func TestUpdate(t *testing.T) {
224224
pingResponse: make(chan struct{}, 10), // HACK: This is to avoid the current deadlock
225225
sendQueue: make(chan []byte, 256),
226226
}
227-
chatbot.init(mockSocket)
227+
chatbot.init(&mockSocket)
228228
conf := map[string]string{
229229
"nick": "test", "password": "testxyz", "server": "localhost"}
230230
channels = append(channels, &NEW_CHANNEL)

0 commit comments

Comments
 (0)