...
1 package endpoint_test
2
3 import (
4 "context"
5 "fmt"
6
7 "github.com/go-kit/kit/endpoint"
8 )
9
10 func ExampleChain() {
11 e := endpoint.Chain(
12 annotate("first"),
13 annotate("second"),
14 annotate("third"),
15 )(myEndpoint)
16
17 if _, err := e(ctx, req); err != nil {
18 panic(err)
19 }
20
21
22
23
24
25
26
27
28
29 }
30
31 var (
32 ctx = context.Background()
33 req = struct{}{}
34 )
35
36 func annotate(s string) endpoint.Middleware {
37 return func(next endpoint.Endpoint) endpoint.Endpoint {
38 return func(ctx context.Context, request interface{}) (interface{}, error) {
39 fmt.Println(s, "pre")
40 defer fmt.Println(s, "post")
41 return next(ctx, request)
42 }
43 }
44 }
45
46 func myEndpoint(context.Context, interface{}) (interface{}, error) {
47 fmt.Println("my endpoint!")
48 return struct{}{}, nil
49 }
50
View as plain text