chain

package
v0.3.15 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 13, 2025 License: Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTooManyHandle = errors.Errorf("too many handlers, at most '%d' handlers is allowed", abortIndex)
	ErrNoHandle      = errors.New("chain has no handlers, forget call Use()?")
)

Functions

This section is empty.

Types

type Chain

type Chain struct {
	// contains filtered or unexported fields
}

Chain represents a chain of handlers.

func (*Chain) Handle

func (chain *Chain) Handle(tmp Temporary) error

Handle executes the chain of handlers.

func (*Chain) Use

func (chain *Chain) Use(handlers ...Handler) error

Use adds handlers to the chain.

type Context

type Context interface {
	Temporary
	Abort()                   // Abort the chain execution.
	AbortWithError(err error) // Abort the chain execution with a custom error.
	IsAborted() bool          // Check if the chain execution is aborted.
	Next()                    // Continue to the next handler in the chain.
}

Context defines the interface for the context passed through the chain.

type Handler

type Handler interface {
	Execute(ctx Context)
}

Handler defines the interface for a chain handler.

type Temporary added in v0.3.12

type Temporary interface {
	Set(key string, value any)  // Set a value in the context.
	Get(key string) (any, bool) // Get a value from the context.
	Request() any               // Get the request associated with the context.
}

type UnaryHandler added in v0.3.12

type UnaryHandler[T any] func(ctx context.Context, in T) (any, error)

type UnaryInterceptor added in v0.3.12

type UnaryInterceptor[T any] func(ctx context.Context, in T, handler UnaryHandler[T]) (resp any, err error)

func ChainUnaryInterceptors added in v0.3.12

func ChainUnaryInterceptors[T any](interceptors []UnaryInterceptor[T]) UnaryInterceptor[T]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL