7 // Endpoint is the fundamental building block of servers and clients.
8 // It represents a single RPC method.
9 type Endpoint func(ctx context.Context, request interface{}) (response interface{}, err error)
11 // Nop is an endpoint that does nothing and returns a nil error.
13 func Nop(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil }
15 // Middleware is a chainable behavior modifier for endpoints.
16 type Middleware func(Endpoint) Endpoint
18 // Chain is a helper function for composing middlewares. Requests will
19 // traverse them in the order they're declared. That is, the first middleware
20 // is treated as the outermost middleware.
21 func Chain(outer Middleware, others ...Middleware) Middleware {
22 return func(next Endpoint) Endpoint {
23 for i := len(others) - 1; i >= 0; i-- { // reverse
24 next = others[i](next)