|
if ne, ok := err.(*net.OpError); ok { |
I have also seen such code snippets in the gin framework. Here you have done this again. Is it possible to encapsulate an IsBroken func instead of writing this every time.
Just like below:
// IsBroken check for a broken connection, as it is not really a
// condition that warrants a panic stack trace.
func IsBroken(err interface{}) bool {
if ne, ok := err.(*net.OpError); ok {
if se, ok := ne.Err.(*os.SyscallError); ok {
errMsg := strings.ToLower(se.Error())
debugPrintf("os syscall error:%s", errMsg)
if strings.Contains(errMsg, "broken pipe") ||
strings.Contains(errMsg, "reset by peer"){
return true
}
}
}
return false
}
zap/zap.go
Line 72 in 062a8ac
I have also seen such code snippets in the gin framework. Here you have done this again. Is it possible to encapsulate an IsBroken func instead of writing this every time.
Just like below: