github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/internal/ratelimiter/config/config.go (about)

     1  package config
     2  
     3  import (
     4  	"github.com/ydb-platform/ydb-go-sdk/v3/internal/config"
     5  	"github.com/ydb-platform/ydb-go-sdk/v3/trace"
     6  )
     7  
     8  // Config is a configuration of ratelimiter client
     9  type Config struct {
    10  	config.Common
    11  
    12  	trace *trace.Ratelimiter
    13  }
    14  
    15  // Trace returns trace over ratelimiter calls
    16  func (c Config) Trace() *trace.Ratelimiter {
    17  	return c.trace
    18  }
    19  
    20  type Option func(c *Config)
    21  
    22  // WithTrace appends ratelimiter trace to early defined traces
    23  func WithTrace(trace trace.Ratelimiter, opts ...trace.RatelimiterComposeOption) Option {
    24  	return func(c *Config) {
    25  		c.trace = c.trace.Compose(&trace, opts...)
    26  	}
    27  }
    28  
    29  // With applies common configuration params
    30  func With(config config.Common) Option {
    31  	return func(c *Config) {
    32  		c.Common = config
    33  	}
    34  }
    35  
    36  func New(opts ...Option) Config {
    37  	c := Config{
    38  		trace: &trace.Ratelimiter{},
    39  	}
    40  	for _, o := range opts {
    41  		if o != nil {
    42  			o(&c)
    43  		}
    44  	}
    45  
    46  	return c
    47  }