January 2020
Intermediate to advanced
640 pages
16h 56m
English
The next service that we will be implementing is the Aggregator type. As shown in the following code snippet, it stores a vendor ID, a list of provider addresses to query, and a list of gRPC clients for those addresses:
type Aggregator struct { vendorID string providerAddrs []string clients []proto.QuoteServiceClient } func NewAggregator(vendorID string, providerAddrs []string) *Aggregator { return &Aggregator{ vendorID: vendorID, providerAddrs: providerAddrs, } }
The gRPC clients are lazily created when the Serve method is invoked:
func (a *Aggregator) Serve(ctx context.Context) (string, error) { tracer := tracer.MustGetTracer(a.vendorID) tracerClientOpt := grpc.WithUnaryInterceptor(otgrpc.OpenTracingClientInterceptor(tracer)) ...