IsConnectionRefusedError returns true if the given error is due to a connection being actively refused.
(err error)
| 1630 | |
| 1631 | // IsConnectionRefusedError returns true if the given error is due to a connection being actively refused. |
| 1632 | func IsConnectionRefusedError(err error) bool { |
| 1633 | if err == nil { |
| 1634 | return false |
| 1635 | } |
| 1636 | |
| 1637 | var errorMessage string |
| 1638 | switch runtime.GOOS { |
| 1639 | case "linux", "darwin": |
| 1640 | errorMessage = "connection refused" |
| 1641 | case "windows": |
| 1642 | errorMessage = "target machine actively refused" |
| 1643 | } |
| 1644 | |
| 1645 | return strings.Contains(err.Error(), errorMessage) |
| 1646 | } |
| 1647 | |
| 1648 | // ConfigDuration is a time.Duration that supports JSON marshalling/unmarshalling. |
| 1649 | // Underlying duration cannot be embedded due to requiring reflect access for mergo. |