From 595663dd37a83b2b87dbcde5e598441c48f3dd27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Fri, 23 Jul 2021 22:00:46 +0200 Subject: [PATCH] otelmemcache: Refactor option type (#855) --- .../gomemcache/memcache/otelmemcache/config.go | 14 +++++++++++--- .../gomemcache/memcache/otelmemcache/gomemcache.go | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/config.go b/instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/config.go index 68c3ff2ede2..1041555197b 100644 --- a/instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/config.go +++ b/instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/config.go @@ -23,12 +23,20 @@ type config struct { } // Option is used to configure the client. -type Option func(*config) +type Option interface { + apply(*config) +} + +type optionFunc func(*config) + +func (o optionFunc) apply(c *config) { + o(c) +} // WithTracerProvider specifies a tracer provider to use for creating a tracer. // If none is specified, the global provider is used. func WithTracerProvider(provider oteltrace.TracerProvider) Option { - return func(cfg *config) { + return optionFunc(func(cfg *config) { cfg.tracerProvider = provider - } + }) } diff --git a/instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/gomemcache.go b/instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/gomemcache.go index 41dd6d80f39..cf2cf8ddb53 100644 --- a/instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/gomemcache.go +++ b/instrumentation/github.com/bradfitz/gomemcache/memcache/otelmemcache/gomemcache.go @@ -49,7 +49,7 @@ type Client struct { func NewClientWithTracing(client *memcache.Client, opts ...Option) *Client { cfg := &config{} for _, o := range opts { - o(cfg) + o.apply(cfg) } if cfg.tracerProvider == nil {