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

     1  // Code generated by github.com/ecordell/optgen. DO NOT EDIT.
     2  package server
     3  
     4  import (
     5  	defaults "github.com/creasty/defaults"
     6  	helpers "github.com/ecordell/optgen/helpers"
     7  )
     8  
     9  type CacheConfigOption func(c *CacheConfig)
    10  
    11  // NewCacheConfigWithOptions creates a new CacheConfig with the passed in options set
    12  func NewCacheConfigWithOptions(opts ...CacheConfigOption) *CacheConfig {
    13  	c := &CacheConfig{}
    14  	for _, o := range opts {
    15  		o(c)
    16  	}
    17  	return c
    18  }
    19  
    20  // NewCacheConfigWithOptionsAndDefaults creates a new CacheConfig with the passed in options set starting from the defaults
    21  func NewCacheConfigWithOptionsAndDefaults(opts ...CacheConfigOption) *CacheConfig {
    22  	c := &CacheConfig{}
    23  	defaults.MustSet(c)
    24  	for _, o := range opts {
    25  		o(c)
    26  	}
    27  	return c
    28  }
    29  
    30  // ToOption returns a new CacheConfigOption that sets the values from the passed in CacheConfig
    31  func (c *CacheConfig) ToOption() CacheConfigOption {
    32  	return func(to *CacheConfig) {
    33  		to.Name = c.Name
    34  		to.MaxCost = c.MaxCost
    35  		to.NumCounters = c.NumCounters
    36  		to.Metrics = c.Metrics
    37  		to.Enabled = c.Enabled
    38  		to.defaultTTL = c.defaultTTL
    39  	}
    40  }
    41  
    42  // DebugMap returns a map form of CacheConfig for debugging
    43  func (c CacheConfig) DebugMap() map[string]any {
    44  	debugMap := map[string]any{}
    45  	debugMap["Name"] = helpers.DebugValue(c.Name, false)
    46  	debugMap["MaxCost"] = helpers.DebugValue(c.MaxCost, false)
    47  	debugMap["NumCounters"] = helpers.DebugValue(c.NumCounters, false)
    48  	debugMap["Metrics"] = helpers.DebugValue(c.Metrics, false)
    49  	debugMap["Enabled"] = helpers.DebugValue(c.Enabled, false)
    50  	return debugMap
    51  }
    52  
    53  // CacheConfigWithOptions configures an existing CacheConfig with the passed in options set
    54  func CacheConfigWithOptions(c *CacheConfig, opts ...CacheConfigOption) *CacheConfig {
    55  	for _, o := range opts {
    56  		o(c)
    57  	}
    58  	return c
    59  }
    60  
    61  // WithOptions configures the receiver CacheConfig with the passed in options set
    62  func (c *CacheConfig) WithOptions(opts ...CacheConfigOption) *CacheConfig {
    63  	for _, o := range opts {
    64  		o(c)
    65  	}
    66  	return c
    67  }
    68  
    69  // WithName returns an option that can set Name on a CacheConfig
    70  func WithName(name string) CacheConfigOption {
    71  	return func(c *CacheConfig) {
    72  		c.Name = name
    73  	}
    74  }
    75  
    76  // WithMaxCost returns an option that can set MaxCost on a CacheConfig
    77  func WithMaxCost(maxCost string) CacheConfigOption {
    78  	return func(c *CacheConfig) {
    79  		c.MaxCost = maxCost
    80  	}
    81  }
    82  
    83  // WithNumCounters returns an option that can set NumCounters on a CacheConfig
    84  func WithNumCounters(numCounters int64) CacheConfigOption {
    85  	return func(c *CacheConfig) {
    86  		c.NumCounters = numCounters
    87  	}
    88  }
    89  
    90  // WithMetrics returns an option that can set Metrics on a CacheConfig
    91  func WithMetrics(metrics bool) CacheConfigOption {
    92  	return func(c *CacheConfig) {
    93  		c.Metrics = metrics
    94  	}
    95  }
    96  
    97  // WithEnabled returns an option that can set Enabled on a CacheConfig
    98  func WithEnabled(enabled bool) CacheConfigOption {
    99  	return func(c *CacheConfig) {
   100  		c.Enabled = enabled
   101  	}
   102  }