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 ¶
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>