@@ -6,20 +6,20 @@ import (
66
77// Endpoint is the fundamental building block of servers and clients.
88// It represents a single RPC method.
9- type Endpoint func (ctx context.Context , request interface {} ) (response interface {} , err error )
9+ type Endpoint [ Req any , Resp any ] func (ctx context.Context , request Req ) (response Resp , err error )
1010
1111// Nop is an endpoint that does nothing and returns a nil error.
1212// Useful for tests.
1313func Nop (context.Context , interface {}) (interface {}, error ) { return struct {}{}, nil }
1414
1515// Middleware is a chainable behavior modifier for endpoints.
16- type Middleware func (Endpoint ) Endpoint
16+ type Middleware [ Req any , Resp any ] func (Endpoint [ Req , Resp ] ) Endpoint [ Req , Resp ]
1717
1818// Chain is a helper function for composing middlewares. Requests will
1919// traverse them in the order they're declared. That is, the first middleware
2020// is treated as the outermost middleware.
21- func Chain (outer Middleware , others ... Middleware ) Middleware {
22- return func (next Endpoint ) Endpoint {
21+ func Chain [ Req any , Resp any ] (outer Middleware [ Req , Resp ], others ... Middleware [ Req , Resp ] ) Middleware [ Req , Resp ] {
22+ return func (next Endpoint [ Req , Resp ] ) Endpoint [ Req , Resp ] {
2323 for i := len (others ) - 1 ; i >= 0 ; i -- { // reverse
2424 next = others [i ](next )
2525 }
0 commit comments