github.com/authzed/spicedb@v1.32.1-0.20240520085336-ebda56537386/pkg/cmd/datastore/zz_generated.connpool.options.go (about)

     1  // Code generated by github.com/ecordell/optgen. DO NOT EDIT.
     2  package datastore
     3  
     4  import (
     5  	defaults "github.com/creasty/defaults"
     6  	helpers "github.com/ecordell/optgen/helpers"
     7  	"time"
     8  )
     9  
    10  type ConnPoolConfigOption func(c *ConnPoolConfig)
    11  
    12  // NewConnPoolConfigWithOptions creates a new ConnPoolConfig with the passed in options set
    13  func NewConnPoolConfigWithOptions(opts ...ConnPoolConfigOption) *ConnPoolConfig {
    14  	c := &ConnPoolConfig{}
    15  	for _, o := range opts {
    16  		o(c)
    17  	}
    18  	return c
    19  }
    20  
    21  // NewConnPoolConfigWithOptionsAndDefaults creates a new ConnPoolConfig with the passed in options set starting from the defaults
    22  func NewConnPoolConfigWithOptionsAndDefaults(opts ...ConnPoolConfigOption) *ConnPoolConfig {
    23  	c := &ConnPoolConfig{}
    24  	defaults.MustSet(c)
    25  	for _, o := range opts {
    26  		o(c)
    27  	}
    28  	return c
    29  }
    30  
    31  // ToOption returns a new ConnPoolConfigOption that sets the values from the passed in ConnPoolConfig
    32  func (c *ConnPoolConfig) ToOption() ConnPoolConfigOption {
    33  	return func(to *ConnPoolConfig) {
    34  		to.MaxIdleTime = c.MaxIdleTime
    35  		to.MaxLifetime = c.MaxLifetime
    36  		to.MaxLifetimeJitter = c.MaxLifetimeJitter
    37  		to.MaxOpenConns = c.MaxOpenConns
    38  		to.MinOpenConns = c.MinOpenConns
    39  		to.HealthCheckInterval = c.HealthCheckInterval
    40  	}
    41  }
    42  
    43  // DebugMap returns a map form of ConnPoolConfig for debugging
    44  func (c ConnPoolConfig) DebugMap() map[string]any {
    45  	debugMap := map[string]any{}
    46  	debugMap["MaxIdleTime"] = helpers.DebugValue(c.MaxIdleTime, false)
    47  	debugMap["MaxLifetime"] = helpers.DebugValue(c.MaxLifetime, false)
    48  	debugMap["MaxLifetimeJitter"] = helpers.DebugValue(c.MaxLifetimeJitter, false)
    49  	debugMap["MaxOpenConns"] = helpers.DebugValue(c.MaxOpenConns, false)
    50  	debugMap["MinOpenConns"] = helpers.DebugValue(c.MinOpenConns, false)
    51  	debugMap["HealthCheckInterval"] = helpers.DebugValue(c.HealthCheckInterval, false)
    52  	return debugMap
    53  }
    54  
    55  // ConnPoolConfigWithOptions configures an existing ConnPoolConfig with the passed in options set
    56  func ConnPoolConfigWithOptions(c *ConnPoolConfig, opts ...ConnPoolConfigOption) *ConnPoolConfig {
    57  	for _, o := range opts {
    58  		o(c)
    59  	}
    60  	return c
    61  }
    62  
    63  // WithOptions configures the receiver ConnPoolConfig with the passed in options set
    64  func (c *ConnPoolConfig) WithOptions(opts ...ConnPoolConfigOption) *ConnPoolConfig {
    65  	for _, o := range opts {
    66  		o(c)
    67  	}
    68  	return c
    69  }
    70  
    71  // WithMaxIdleTime returns an option that can set MaxIdleTime on a ConnPoolConfig
    72  func WithMaxIdleTime(maxIdleTime time.Duration) ConnPoolConfigOption {
    73  	return func(c *ConnPoolConfig) {
    74  		c.MaxIdleTime = maxIdleTime
    75  	}
    76  }
    77  
    78  // WithMaxLifetime returns an option that can set MaxLifetime on a ConnPoolConfig
    79  func WithMaxLifetime(maxLifetime time.Duration) ConnPoolConfigOption {
    80  	return func(c *ConnPoolConfig) {
    81  		c.MaxLifetime = maxLifetime
    82  	}
    83  }
    84  
    85  // WithMaxLifetimeJitter returns an option that can set MaxLifetimeJitter on a ConnPoolConfig
    86  func WithMaxLifetimeJitter(maxLifetimeJitter time.Duration) ConnPoolConfigOption {
    87  	return func(c *ConnPoolConfig) {
    88  		c.MaxLifetimeJitter = maxLifetimeJitter
    89  	}
    90  }
    91  
    92  // WithMaxOpenConns returns an option that can set MaxOpenConns on a ConnPoolConfig
    93  func WithMaxOpenConns(maxOpenConns int) ConnPoolConfigOption {
    94  	return func(c *ConnPoolConfig) {
    95  		c.MaxOpenConns = maxOpenConns
    96  	}
    97  }
    98  
    99  // WithMinOpenConns returns an option that can set MinOpenConns on a ConnPoolConfig
   100  func WithMinOpenConns(minOpenConns int) ConnPoolConfigOption {
   101  	return func(c *ConnPoolConfig) {
   102  		c.MinOpenConns = minOpenConns
   103  	}
   104  }
   105  
   106  // WithHealthCheckInterval returns an option that can set HealthCheckInterval on a ConnPoolConfig
   107  func WithHealthCheckInterval(healthCheckInterval time.Duration) ConnPoolConfigOption {
   108  	return func(c *ConnPoolConfig) {
   109  		c.HealthCheckInterval = healthCheckInterval
   110  	}
   111  }