Use defer when expected
This commit is contained in:
parent
49d553c9b8
commit
397b56dc9d
10
writer.go
10
writer.go
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue