config

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// Can be "none" or "redis".
	Type string
	// Prefix to use for cache keys.
	KeyPrefix string
	// Has no effect if type is "none".
	TTL TTL
	// Redis specific settings.
	Redis Redis
}

type Category

type Category struct {
	Engines                  []engines.Name
	RequiredEngines          []engines.Name
	RequiredByOriginEngines  []engines.Name
	PreferredEngines         []engines.Name
	PreferredByOriginEngines []engines.Name
	Ranking                  CategoryRanking
	Timings                  CategoryTimings
}

type CategoryEngineRanking

type CategoryEngineRanking struct {
	Mul   float64 `koanf:"mul"`
	Const float64 `koanf:"const"`
}

type CategoryRanking

type CategoryRanking struct {
	REXP    float64                          `koanf:"rexp"`
	A       float64                          `koanf:"a"`
	B       float64                          `koanf:"b"`
	C       float64                          `koanf:"c"`
	D       float64                          `koanf:"d"`
	TRA     float64                          `koanf:"tra"`
	TRB     float64                          `koanf:"trb"`
	TRC     float64                          `koanf:"trc"`
	TRD     float64                          `koanf:"trd"`
	Engines map[string]CategoryEngineRanking `koanf:"engines"`
}

func EmptyRanking

func EmptyRanking(engs []engines.Name) CategoryRanking

type CategoryTimings

type CategoryTimings struct {
	// Maximum amount of time to wait for the PreferredEngines (or ByOrigin) to respond.
	// If the search is still waiting for the RequiredEngines (or ByOrigin) after this time, the search will continue.
	PreferredTimeout time.Duration
	// Hard timeout after which the search is forcefully stopped (even if the engines didn't respond).
	HardTimeout time.Duration
	// Colly delay.
	Delay time.Duration
	// Colly random delay.
	RandomDelay time.Duration
	// Colly parallelism.
	Parallelism int
}

Delegates Delay, RandomDelay, Parallelism to colly.Collector.Limit().

type Config

type Config struct {
	Server     Server
	Categories map[category.Name]Category
}

func New

func New() Config

func (*Config) Load

func (c *Config) Load(configPath string)

type ImageProxy

type ImageProxy struct {
	Salt    string
	Timeout time.Duration
}

type ReaderCache

type ReaderCache struct {
	// Can be "none" or "redis".
	Type string `koanf:"type"`
	// Prefix to use for cache keys.
	KeyPrefix string `koanf:"keyprefix"`
	// Has no effect if type is "none".
	TTL ReaderTTL `koanf:"ttl"`
	// Redis specific settings.
	Redis Redis `koanf:"redis"`
}

ReaderCache is format in which the config is read from the config file and environment variables.

type ReaderCategory

type ReaderCategory struct {
	REngines map[string]ReaderCategoryEngine `koanf:"engines"`
	Ranking  CategoryRanking                 `koanf:"ranking"`
	RTimings ReaderCategoryTimings           `koanf:"timings"`
}

ReaderCategory is format in which the config is read from the config file and environment variables.

type ReaderCategoryEngine

type ReaderCategoryEngine struct {
	// If false, the engine will not be used and other options will be ignored.
	Enabled bool `koanf:"enabled"`
	// If true, the engine will be awaited unless the hard timeout is reached.
	Required bool `koanf:"required"`
	// If true, the fastest engine that has this engine in "Origins" will be awaited unless the hard timeout is reached.
	// This means that we want to get results from this engine or any engine that has this engine in "Origins", whichever responds the fastest.
	RequiredByOrigin bool `koanf:"requiredbyorigin"`
	// If true, the engine will be awaited unless the preferred timeout is reached.
	Preferred bool `koanf:"preferred"`
	// If true, the fastest engine that has this engine in "Origins" will be awaited unless the preferred timeout is reached.
	// This means that we want to get results from this engine or any engine that has this engine in "Origins", whichever responds the fastest.
	PreferredByOrigin bool `koanf:"preferredbyorigin"`
}

ReaderEngine is format in which the config is read from the config file and environment variables.

type ReaderCategoryTimings

type ReaderCategoryTimings struct {
	// Maximum amount of time to wait for the PreferredEngines (or ByOrigin) to respond.
	// If the search is still waiting for the RequiredEngines (or ByOrigin) after this time, the search will continue.
	PreferredTimeout string `koanf:"preferredtimeout"`
	// Hard timeout after which the search is forcefully stopped (even if the engines didn't respond).
	HardTimeout string `koanf:"hardtimeout"`
	// Colly delay.
	Delay string `koanf:"delay"`
	// Colly random delay.
	RandomDelay string `koanf:"randomdelay"`
	// Colly parallelism.
	Parallelism int `koanf:"parallelism"`
}

ReaderTimings is format in which the config is read from the config file and environment variables. In <number><unit> format. Example: 1s, 1m, 1h, 1d, 1w, 1M, 1y. If unit is not specified, it is assumed to be milliseconds. Delegates Delay, RandomDelay, Parallelism to colly.Collector.Limit().

type ReaderConfig

type ReaderConfig struct {
	Server      ReaderServer                     `koanf:"server"`
	RCategories map[category.Name]ReaderCategory `koanf:"categories"`
}

ReaderConfig is format in which the config is read from the config file and environment variables.

type ReaderImageProxy

type ReaderImageProxy struct {
	Salt    string `koanf:"salt"`
	Timeout string `koanf:"timeout"`
}

ReaderProxy is format in which the config is read from the config file and environment variables. In <number><unit> format. Example: 1s, 1m, 1h, 1d, 1w, 1M, 1y. If unit is not specified, it is assumed to be milliseconds.

type ReaderServer

type ReaderServer struct {
	// Environment in which the server is running (normal or lambda).
	Environment string `koanf:"environment"`
	// Port on which the API server listens.
	Port int `koanf:"port"`
	// URLs used for CORS (wildcards allowed).
	// Comma separated.
	FrontendUrls string `koanf:"frontendurls"`
	// Cache settings.
	Cache ReaderCache `koanf:"cache"`
	// Image proxy settings.
	ImageProxy ReaderImageProxy `koanf:"imageproxy"`
}

ReaderServer is format in which the config is read from the config file and environment variables.

type ReaderTTL

type ReaderTTL struct {
	// How long to store the results in cache.
	// Setting this to 0 caches the results forever.
	Time string `koanf:"time"`
}

ReaderTTL is format in which the config is read from the config file and environment variables. In <number><unit> format. Example: 1s, 1m, 1h, 1d, 1w, 1M, 1y. If unit is not specified, it is assumed to be milliseconds.

type Redis

type Redis struct {
	Host     string `koanf:"host"`
	Port     uint16 `koanf:"port"`
	Password string `koanf:"password"`
	Database uint8  `koanf:"database"`
}

type Server

type Server struct {
	// Environment in which the server is running (normal or lambda).
	Environment string
	// Port on which the API server listens.
	Port int
	// URLs used for CORS (wildcards allowed).
	FrontendUrls []string
	// Cache settings.
	Cache Cache
	// Image proxy settings.
	ImageProxy ImageProxy
}

type TTL

type TTL struct {
	// How long to store the results in cache.
	// Setting this to 0 caches the results forever.
	Time time.Duration
}

Jump to

Keyboard shortcuts

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