Documentation ¶
Overview ¶
Package classifier provides a way to classify an occurred error.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action int
Action is the type returned by a Classifier to indicate how the Retrier should proceed.
const ( // Succeed indicates the Retrier should // treat this value as a success. Succeed Action = iota // Fail indicates the Retrier should // treat this value as a hard failure and not retry. Fail // Retry indicates the Retrier should // treat this value as a soft failure and retry. Retry // Unknown indicates the Retrier should // apply another Classifier to make a decision. Unknown )
type BlacklistClassifier ¶
type BlacklistClassifier []error
BlacklistClassifier classifies errors based on a blacklist. If the error is nil, it returns Succeed; if the error is in the blacklist, it returns Fail; otherwise, it returns Retry.
func (BlacklistClassifier) Classify ¶
func (list BlacklistClassifier) Classify(err error) Action
Classify implements the Classifier interface.
type Classifier ¶
Classifier is the interface implemented by anything that can classify Errors for a Retrier.
type DefaultClassifier ¶
type DefaultClassifier struct{}
DefaultClassifier classifies errors in the simplest way possible. If the error is nil, it returns Succeed, otherwise it returns Retry.
func (DefaultClassifier) Classify ¶
func (c DefaultClassifier) Classify(err error) Action
Classify implements the Classifier interface.
type FunctionalClassifier ¶
The FunctionalClassifier type is an adapter to allow the use of ordinary functions as Classifier. If f is a function with the appropriate signature, HandlerFunc(f) is a Classifier that calls f.
var ( // NetworkErrorClassifier classifies network errors. // If the error is nil, it returns Succeed; // if the error is net.Error, it returns Retry when // timeout occurred or error is temporary // or returns Fail; // otherwise, it returns Unknown. NetworkErrorClassifier FunctionalClassifier = func(err error) Action { if err == nil { return Succeed } if err, ok := err.(net.Error); ok { if err.Timeout() || err.Temporary() { return Retry } return Fail } return Unknown } )
func (FunctionalClassifier) Classify ¶
func (f FunctionalClassifier) Classify(err error) Action
Classify implements the Classifier interface.
type WhitelistClassifier ¶
type WhitelistClassifier []error
WhitelistClassifier classifies errors based on a whitelist. If the error is nil, it returns Succeed; if the error is in the whitelist, it returns Retry; otherwise, it returns Fail.
func (WhitelistClassifier) Classify ¶
func (list WhitelistClassifier) Classify(err error) Action
Classify implements the Classifier interface.