config

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: Apache-2.0 Imports: 7 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 Api added in v1.1.1

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

type Backend added in v1.1.1

type Backend struct {
	ID                       string        `yaml:"id"`
	Enabled                  bool          `yaml:"enabled"`
	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.
	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.
}

func (*Backend) Clone added in v1.1.1

func (b *Backend) Clone() *Backend

Clone - deep copy, obviously returns a new pointer.

type Cache

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

func LoadConfig

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

func MustTestConfig added in v1.4.4

func MustTestConfig() *Cache

MustTestConfig panics on nil to simplify usage in tests.

func NewTestConfig added in v1.4.4

func NewTestConfig() *Cache

NewTestConfig returns a fully-populated *Cache mirroring the YAML you shared, including all computed "virtual" fields that LoadConfig sets (QueryBytes, HeadersMap, PathBytes, Backends' *Bytes fields, SoftMemoryLimit, and AtomicEnabled).

func (*Cache) Api added in v1.1.1

func (c *Cache) Api() *Api

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) Refresh added in v1.1.1

func (c *Cache) Refresh() *Refresh

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"`
	Eviction            *Eviction        `yaml:"eviction"`
	Refresh             *Refresh         `yaml:"refresh"`
	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 Config added in v1.1.1

type Config interface {
	IsProd() bool
	IsDebug() bool
	IsEnabled() bool
	SetEnabled(v bool)
	Runtime() *Runtime
	Api() *Api
	Upstream() *Upstream
	Data() *Data
	Refresh() *Refresh
	Eviction() *Eviction
	Storage() *Storage
	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%
	ScanRate  int64   `yaml:"scan_rate"`
	Replicas  int32   `yaml:"replicas"`
}

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 Logs added in v0.9.3

type Logs struct {
	Level string `yaml:"level"` // Any zerolog.Level.
	Stats bool   `yaml:"stats"` // Should the statistic like num evictions, refreshes, rps, memory usage and so on be written in /std/out?
}

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 Probe added in v0.9.9

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

type Refresh

type Refresh 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)
	Rate     int           `yaml:"rate"`      // Rate limiting to external backend.
	ScanRate int64         `yaml:"scan_rate"` // Rate limiting of num scans items per second.
	// 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)
	Replicas    int32   `yaml:"replicas"`
}

type Rule

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

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 RuleRefresh added in v1.0.1

type RuleRefresh 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 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 Storage

type Storage struct {
	Size            int64 `yaml:"size"`
	SoftMemoryLimit int64
	HardMemoryLimit int64
}

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