Skip to content

Commit

Permalink
otelmemcache: Refactor option type (#855)
Browse files Browse the repository at this point in the history
  • Loading branch information
pellared authored Jul 23, 2021
1 parent 05ef436 commit 595663d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 595663d

Please sign in to comment.