OSDN Git Service

delete miner
[bytom/vapor.git] / vendor / github.com / go-kit / kit / endpoint / endpoint.go
1 package endpoint
2
3 import (
4         "context"
5 )
6
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)
10
11 // Nop is an endpoint that does nothing and returns a nil error.
12 // Useful for tests.
13 func Nop(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil }
14
15 // Middleware is a chainable behavior modifier for endpoints.
16 type Middleware func(Endpoint) Endpoint
17
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)
25                 }
26                 return outer(next)
27         }
28 }