intercept

package
v0.1.0-preview.4 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package intercept provides typed, reflection-free invocation decorators used by generated Spice boundaries.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interceptor

type Interceptor[Request, Response any] func(
	context.Context,
	Request,
	Invocation[Request, Response],
) (Response, error)

Interceptor wraps one typed invocation. It may inspect or replace the request/response, short-circuit, or call next. It owns no global registry and cannot select methods by string or reflection.

type Invocation

type Invocation[Request, Response any] func(
	context.Context,
	Request,
) (Response, error)

Invocation is one ordinary typed operation. Generated code supplies the direct method call as the terminal invocation.

func Chain

func Chain[Request, Response any](
	terminal Invocation[Request, Response],
	interceptors ...Interceptor[Request, Response],
) (Invocation[Request, Response], error)

Chain validates and freezes an interceptor chain. The first interceptor is outermost, matching ordinary nested Go function composition. The returned invocation rejects a nil context before user code executes.

Example
invocation, err := Chain(
	func(_ context.Context, request string) (string, error) {
		return "hello " + request, nil
	},
	func(
		ctx context.Context,
		request string,
		next Invocation[string, string],
	) (string, error) {
		return next(ctx, strings.ToUpper(request))
	},
)
if err != nil {
	fmt.Println(err)
	return
}
response, err := invocation(context.Background(), "spice")
fmt.Println(response, err)
Output:
hello SPICE <nil>

Jump to

Keyboard shortcuts

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