github.com/ydb-platform/ydb-go-sdk/v3@v3.89.2/internal/scheme/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 scheme client
     9  type Config struct {
    10  	config.Common
    11  
    12  	databaseName string
    13  	trace        *trace.Scheme
    14  }
    15  
    16  // Trace returns trace over scheme client calls
    17  func (c *Config) Trace() *trace.Scheme {
    18  	return c.trace
    19  }
    20  
    21  // Database returns database name
    22  func (c *Config) Database() string {
    23  	return c.databaseName
    24  }
    25  
    26  type Option func(c *Config)
    27  
    28  // WithTrace appends scheme trace to early defined traces
    29  func WithTrace(trace trace.Scheme, opts ...trace.SchemeComposeOption) Option {
    30  	return func(c *Config) {
    31  		c.trace = c.trace.Compose(&trace, opts...)
    32  	}
    33  }
    34  
    35  // WithDatabaseName applies database name
    36  func WithDatabaseName(dbName string) Option {
    37  	return func(c *Config) {
    38  		c.databaseName = dbName
    39  	}
    40  }
    41  
    42  // With applies common configuration params
    43  func With(config config.Common) Option {
    44  	return func(c *Config) {
    45  		c.Common = config
    46  	}
    47  }
    48  
    49  func New(opts ...Option) *Config {
    50  	c := &Config{
    51  		trace: &trace.Scheme{},
    52  	}
    53  	for _, opt := range opts {
    54  		if opt != nil {
    55  			opt(c)
    56  		}
    57  	}
    58  
    59  	return c
    60  }