config

package
v1.8.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 2, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Prod  = "prod"
	Dev   = "dev"
	Debug = "debug"
	Test  = "test"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Admission added in v1.6.0

type Admission struct {
	Enabled             bool        `yaml:"enabled"`
	IsEnabled           atomic.Bool // virtual field; sets while init.
	Capacity            int         `yaml:"capacity"`
	Shards              int         `yaml:"shards"`
	MinTableLenPerShard int         `yaml:"min_table_len_per_shard"`
	SampleMultiplier    int         `yaml:"sample_multiplier"`
	DoorBitsPerCounter  int         `yaml:"door_bits_per_counter"`
}

type Api added in v1.1.1

type Api struct {
	Name        string `yaml:"name"` // api server name
	Port        string `yaml:"port"` // port of api server
	NetListener net.Listener
}

type Backend added in v1.1.1

type Backend struct {
	ID                       string `yaml:"id"`
	IDBytes                  []byte
	Enabled                  bool          `yaml:"enabled"`
	Policy                   string        `yaml:"policy"`
	Scheme                   string        `yaml:"scheme"` // http or https
	SchemeBytes              []byte        // virtual field, Scheme converted to []byte
	Host                     string        `yaml:"host"` // backend.example.com
	HostBytes                []byte        // virtual field, Host converted to []byte
	Rate                     int           `yaml:"rate"`                   // Rate limiting reqs to backend per second.
	Concurrency              int           `yaml:"concurrency"`            // Mux concurrency (in-flight reqs).
	Timeout                  time.Duration `yaml:"timeout"`                // Timeout for requests to backend.
	MaxTimeout               time.Duration `yaml:"max_timeout"`            // MaxTimeout for requests which are escape Timeout through UseMaxTimeoutHeaderBytes.
	UseMaxTimeoutHeader      string        `yaml:"use_max_timeout_header"` // If the header exists the timeout above will be skipped.
	UseMaxTimeoutHeaderBytes []byte        // The same value but converted into slice bytes.
	Healthcheck              string        `yaml:"healthcheck"` // Healthcheck or readiness probe path
	HealthcheckBytes         []byte        // The same value but converted into slice bytes.
}

type Cache

type Cache struct {
	Cache *CacheBox `yaml:"cache"`
}

func LoadConfig

func LoadConfig(path string) (*Cache, error)

func NewTestConfig added in v1.4.4

func NewTestConfig() *Cache

func (*Cache) Admission added in v1.6.0

func (c *Cache) Admission() *Admission

func (*Cache) Api added in v1.1.1

func (c *Cache) Api() *Api

func (*Cache) Compression added in v1.7.1

func (c *Cache) Compression() *Compression

func (*Cache) Data added in v1.1.1

func (c *Cache) Data() *Data

func (*Cache) Eviction added in v1.1.1

func (c *Cache) Eviction() *Eviction

func (*Cache) ForceGC added in v1.1.1

func (c *Cache) ForceGC() *ForceGC

func (*Cache) IsDebug added in v1.3.0

func (c *Cache) IsDebug() bool

func (*Cache) IsDev

func (c *Cache) IsDev() bool

func (*Cache) IsEnabled added in v1.1.1

func (c *Cache) IsEnabled() bool

func (*Cache) IsProd

func (c *Cache) IsProd() bool

func (*Cache) IsTest

func (c *Cache) IsTest() bool

func (*Cache) K8S added in v1.1.1

func (c *Cache) K8S() *K8S

func (*Cache) Lifetime added in v1.7.0

func (c *Cache) Lifetime() *Lifetime

func (*Cache) Logs added in v1.8.0

func (c *Cache) Logs() *Logs

func (*Cache) Observability added in v1.8.0

func (c *Cache) Observability() *Observability

func (*Cache) Rule added in v1.1.1

func (c *Cache) Rule(path string) (*Rule, bool)

func (*Cache) Runtime added in v1.1.1

func (c *Cache) Runtime() *Runtime

func (*Cache) SetEnabled added in v1.1.1

func (c *Cache) SetEnabled(v bool)

func (*Cache) Storage added in v1.1.1

func (c *Cache) Storage() *Storage

func (*Cache) Upstream added in v1.1.1

func (c *Cache) Upstream() *Upstream

type CacheBox

type CacheBox struct {
	Env                 string `yaml:"env"`
	Enabled             bool   `yaml:"enabled"`
	AtomicEnabled       atomic.Bool
	CheckReloadInterval time.Duration    `yaml:"cfg_reload_check_interval"`
	Logs                *Logs            `yaml:"logs"`
	Runtime             *Runtime         `yaml:"runtime"`
	Api                 *Api             `yaml:"api"`
	Upstream            *Upstream        `yaml:"upstream"`
	Data                *Data            `yaml:"data"`
	Storage             *Storage         `yaml:"storage"`
	Compression         *Compression     `yaml:"compression"`
	Eviction            *Eviction        `yaml:"eviction"`
	Admission           *Admission       `yaml:"admission"`
	Observability       *Observability   `yaml:"observability"`
	Lifetime            *Lifetime        `yaml:"lifetime"`
	ForceGC             *ForceGC         `yaml:"forceGC"`
	Metrics             *Metrics         `yaml:"metrics"`
	K8S                 *K8S             `yaml:"k8s"`
	Rules               map[string]*Rule `yaml:"rules"`
}

type Cluster added in v1.1.1

type Cluster struct {
	Backends []*Backend `yaml:"backends"`
}

type Compression added in v1.7.1

type Compression struct {
	Enabled bool `yaml:"enabled"`
	Level   int  `yaml:"level"`
}

*

  • Compression
  • - Supported levels:
  • CompressNoCompression = 0
  • CompressBestSpeed = 1
  • CompressBestCompression = 9
  • CompressDefaultCompression = 6 // flate.DefaultCompression
  • CompressHuffmanOnly = -2 // flate.HuffmanOnly

type Config added in v1.1.1

type Config interface {
	Logs() *Logs
	IsProd() bool
	IsDebug() bool
	IsEnabled() bool
	SetEnabled(v bool)
	Runtime() *Runtime
	Api() *Api
	Upstream() *Upstream
	Data() *Data
	Lifetime() *Lifetime
	Eviction() *Eviction
	Admission() *Admission
	Observability() *Observability
	Storage() *Storage
	Compression() *Compression
	K8S() *K8S
	ForceGC() *ForceGC
	Rule(path string) (*Rule, bool)
}

type Data added in v1.1.1

type Data struct {
	Dump *Dump `yaml:"dump"`
	Mock *Mock `yaml:"mock"`
}

type Dump

type Dump struct {
	IsEnabled    bool   `yaml:"enabled"`
	Dir          string `yaml:"dump_dir"`
	Name         string `yaml:"dump_name"`
	MaxVersions  int    `yaml:"max_versions"`
	Gzip         bool   `yaml:"gzip"`
	Crc32Control bool   `yaml:"crc32_control_sum"`
}

type Env

type Env struct {
	Value string `yaml:"value"`
}

type Eviction

type Eviction struct {
	Enabled   bool          `yaml:"enabled"`
	SoftLimit float64       `yaml:"soft_limit"` // 0.80 means 80%
	HardLimit float64       `yaml:"hard_limit"` // 0.85 means 85%
	Replicas  int           `yaml:"replicas"`
	Interval  time.Duration `yaml:"check_interval"` // Defines how often the main evictor loop will check the memory limit.
}

type ForceGC added in v0.9.3

type ForceGC struct {
	Enabled  bool          `yaml:"enabled"`
	Interval time.Duration `yaml:"interval"`
}

type K8S added in v0.9.9

type K8S struct {
	Probe Probe `yaml:"probe"`
}

type Lifetime added in v0.9.0

type Lifetime struct {
	Enabled bool    `yaml:"enabled"`
	OnTTL   TTLMode `yaml:"on_ttl"`
	// TTL - refresh TTL (max time life of response item in cache without refreshing).
	TTL      time.Duration `yaml:"ttl"` // e.g. "1d" (responses with 200 status code)
	Replicas int           `yaml:"replicas"`
	Rate     int           `yaml:"rate"` // Rate limiting to external backend.
	// beta определяет коэффициент, используемый для вычисления случайного момента обновления кэша.
	// Чем выше beta, тем чаще кэш будет обновляться до истечения TTL.
	// Формула взята из подхода "stochastic cache expiration" (см. Google Staleness paper):
	// expireTime = ttl * (-beta * ln(random()))
	// Подробнее: RFC 5861 и https://web.archive.org/web/20100829170210/http://labs.google.com/papers/staleness.pdf
	// beta: "0.4"
	Beta          float64     `yaml:"beta"`        // between 0 and 1
	Coefficient   float64     `yaml:"coefficient"` // Starts attempts to renew data after TTL*coefficient=50% (12h if whole TTL is 24h)
	IsRemoveOnTTL atomic.Bool // virtual, computes while init.
}

type LifetimeRule added in v1.7.0

type LifetimeRule struct {
	Enabled bool `yaml:"enabled"`
	// TTL - refresh TTL (max time life of response item in cache without refreshing).
	TTL time.Duration `yaml:"ttl"` // e.g. "1d" (responses with 200 status code)
	// beta определяет коэффициент, используемый для вычисления случайного момента обновления кэша.
	// Чем выше beta, тем чаще кэш будет обновляться до истечения TTL.
	// Формула взята из подхода "stochastic cache expiration" (см. Google Staleness paper):
	// expireTime = ttl * (-beta * ln(random()))
	// Подробнее: RFC 5861 и https://web.archive.org/web/20100829170210/http://labs.google.com/papers/staleness.pdf
	// beta: "0.4"
	Beta        float64 `yaml:"beta"`        // between 0 and 1
	Coefficient float64 `yaml:"coefficient"` // Starts attempts to renew data after TTL*coefficient=50% (12h if whole TTL is 24h)
}

type Logs added in v0.9.3

type Logs struct {
	Level string `yaml:"level"` // Any zerolog.Level.
}

type Metrics added in v0.9.9

type Metrics struct {
	Enabled bool `yaml:"enabled"`
}

type Mock added in v0.9.9

type Mock struct {
	Enabled bool `yaml:"enabled"`
	Length  int  `yaml:"length"`
}

type Observability added in v1.8.0

type Observability struct {
	Enabled            bool          `yaml:"enabled"`              // hard toggle
	ServiceName        string        `yaml:"service_name"`         // "adv-cache"
	ServiceVersion     string        `yaml:"service_version"`      // "dev|prod|test"
	ServiceTenant      string        `yaml:"service_tenant"`       // X_Scope_OTEL_Tenant attribute value
	Exporter           string        `yaml:"exporter"`             // "grpc"|"http"|"stdout"
	Endpoint           string        `yaml:"endpoint"`             // "127.0.0.1:4317" or "127.0.0.1:4318"
	Insecure           bool          `yaml:"insecure"`             // allow insecure local dev
	SamplingMode       SamplingMode  `yaml:"sampling_mode"`        // off|always|ratio
	SamplingRate       float64       `yaml:"sampling_rate"`        // 0..1, used when mode=ratio
	ExportBatchSize    int           `yaml:"export_batch_size"`    // default: 512
	ExportBatchTimeout time.Duration `yaml:"export_batch_timeout"` // default: 2s
	ExportMaxQueue     int           `yaml:"export_max_queue"`     // max queue for export
}

type Probe added in v0.9.9

type Probe struct {
	Timeout time.Duration `yaml:"timeout"`
}

type Rule

type Rule struct {
	Path       string        // Virtual field
	PathBytes  []byte        // Virtual field
	CacheKey   RuleKey       `yaml:"cache_key"`
	CacheValue RuleValue     `yaml:"cache_value"`
	Lifetime   *LifetimeRule `yaml:"refresh"`
}

type RuleKey added in v1.0.1

type RuleKey struct {
	Query      []string          `yaml:"query"` // Параметры, которые будут участвовать в ключе кэширования
	QueryBytes [][]byte          // Virtual field
	Headers    []string          `yaml:"headers"` // Хедеры, которые будут участвовать в ключе кэширования
	HeadersMap map[string][]byte // Virtual field
}

type RuleValue added in v1.0.1

type RuleValue struct {
	Headers    []string            `yaml:"headers"` // Хедеры ответа, которые будут сохранены в кэше вместе с body
	HeadersMap map[string]struct{} // Virtual field
}

type Runtime added in v1.0.2

type Runtime struct {
	Gomaxprocs int `yaml:"gomaxprocs"`
}

type SamplingMode added in v1.8.0

type SamplingMode string
const (
	SamplingOff    SamplingMode = "off"    // never record
	SamplingAlways SamplingMode = "always" // record all
	SamplingRatio  SamplingMode = "ratio"  // ParentBased(TraceIDRatioBased)
)

type Storage

type Storage struct {
	Mode                 string `yaml:"mode"` // sampling or listing
	IsListing            bool   // virtual, fills while init.
	Size                 int64  `yaml:"size"` // soft and hard evictions based on this
	SoftMemoryLimit      int64  // virtual, fills while init.
	HardMemoryLimit      int64  // virtual, fills while init.
	AdmissionMemoryLimit int64  // virtual, fills while init.
}

type TTLMode added in v1.7.0

type TTLMode string
var (
	Remove  TTLMode = "remove"
	Refresh TTLMode = "refresh"
)

type TraefikIntermediateConfig added in v1.0.1

type TraefikIntermediateConfig struct {
	ConfigPath string `yaml:"configPath" mapstructure:"configPath"`
}

type Upstream added in v0.9.0

type Upstream struct {
	Policy  string   `yaml:"policy"`
	Cluster *Cluster `yaml:"cluster"`
	Backend *Backend `yaml:"backend"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL