mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-01 19:07:38 +03:00
23 lines
410 B
Go
23 lines
410 B
Go
package exceptions
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
)
|
|
|
|
type TimeoutError interface {
|
|
Timeout() bool
|
|
}
|
|
|
|
func IsTimeout(err error) bool {
|
|
var netErr net.Error
|
|
if errors.As(err, &netErr) {
|
|
//goland:noinspection GoDeprecation
|
|
//nolint:staticcheck
|
|
return netErr.Temporary() && netErr.Timeout()
|
|
}
|
|
if timeoutErr, isTimeout := Cast[TimeoutError](err); isTimeout {
|
|
return timeoutErr.Timeout()
|
|
}
|
|
return false
|
|
}
|