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