/
client.go
53 lines (45 loc) · 1.46 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Code generated by thriftrw-plugin-yarpc
// @generated
package namefx
import (
fx "go.uber.org/fx"
yarpc "go.uber.org/yarpc"
transport "go.uber.org/yarpc/api/transport"
restriction "go.uber.org/yarpc/api/x/restriction"
thrift "go.uber.org/yarpc/encoding/thrift"
nameclient "go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/extends/nameclient"
)
// Params defines the dependencies for the Name client.
type Params struct {
fx.In
Provider yarpc.ClientConfig
Restriction restriction.Checker `optional:"true"`
}
// Result defines the output of the Name client module. It provides a
// Name client to an Fx application.
type Result struct {
fx.Out
Client nameclient.Interface
// We are using an fx.Out struct here instead of just returning a client
// so that we can add more values or add named versions of the client in
// the future without breaking any existing code.
}
// Client provides a Name client to an Fx application using the given name
// for routing.
//
// fx.Provide(
// namefx.Client("..."),
// newHandler,
// )
func Client(name string, opts ...thrift.ClientOption) interface{} {
return func(p Params) Result {
cc := p.Provider.ClientConfig(name)
if namer, ok := cc.GetUnaryOutbound().(transport.Namer); ok && p.Restriction != nil {
if err := p.Restriction.Check(thrift.Encoding, namer.TransportName()); err != nil {
panic(err.Error())
}
}
client := nameclient.New(cc, opts...)
return Result{Client: client}
}
}