retry: github.com/kamilsk/retry/classifier Index | Files

package classifier

import "github.com/kamilsk/retry/classifier"

Package classifier provides a way to classify an occurred error.

Index

Package Files

blacklist.go classifier.go functional.go whitelist.go

type Action Uses

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 Uses

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 Uses

func (list BlacklistClassifier) Classify(err error) Action

Classify implements the Classifier interface.

type Classifier Uses

type Classifier interface {
    Classify(error) Action
}

Classifier is the interface implemented by anything that can classify Errors for a Retrier.

type DefaultClassifier Uses

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 Uses

func (c DefaultClassifier) Classify(err error) Action

Classify implements the Classifier interface.

type FunctionalClassifier Uses

type FunctionalClassifier func(err error) Action

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 Uses

func (f FunctionalClassifier) Classify(err error) Action

Classify implements the Classifier interface.

type WhitelistClassifier Uses

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 Uses

func (list WhitelistClassifier) Classify(err error) Action

Classify implements the Classifier interface.

Package classifier imports 1 packages (graph). Updated 2017-12-23. Refresh now. Tools for package owners.