Use defer when expected

This commit is contained in:
Olivier Poitrey 2017-06-05 12:43:37 -07:00
parent 49d553c9b8
commit 397b56dc9d
1 changed files with 4 additions and 6 deletions

View File

@ -41,17 +41,15 @@ func SyncWriter(w io.Writer) io.Writer {
// Write implements the io.Writer interface. // Write implements the io.Writer interface.
func (s *syncWriter) Write(p []byte) (n int, err error) { func (s *syncWriter) Write(p []byte) (n int, err error) {
s.mu.Lock() s.mu.Lock()
n, err = s.lw.Write(p) defer s.mu.Unlock()
s.mu.Unlock() return s.lw.Write(p)
return
} }
// WriteLevel implements the LevelWriter interface. // WriteLevel implements the LevelWriter interface.
func (s *syncWriter) WriteLevel(l Level, p []byte) (n int, err error) { func (s *syncWriter) WriteLevel(l Level, p []byte) (n int, err error) {
s.mu.Lock() s.mu.Lock()
n, err = s.lw.WriteLevel(l, p) defer s.mu.Unlock()
s.mu.Unlock() return s.lw.WriteLevel(l, p)
return
} }
type multiLevelWriter struct { type multiLevelWriter struct {