config

package
v0.29.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2024 License: AGPL-3.0 Imports: 15 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", "redis" or "dynamodb".
	Type string
	// Prefix to use for cache keys.
	KeyPrefix string
	// Has no effect if type is "none".
	TTL TTL
	// Redis specific settings.
	Redis Redis
	// DynamoDB specific settings.
	DynamoDB DynamoDB
}

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

func ReqPrefOthRanking added in v0.29.0

func ReqPrefOthRanking(req []engines.Name, pref []engines.Name, oth []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
	Exchange   Exchange
}

func New

func New() Config

func (*Config) Load

func (c *Config) Load(configPath string)

type DynamoDB added in v0.25.0

type DynamoDB struct {
	// Set to "global" or leave empty for a DynamoDB global table.
	Region string `koanf:"region"`
	Table  string `koanf:"table"`
	// Endpoint is used for local testing.
	Endpoint string `koanf:"endpoint"`
}

type Exchange added in v0.26.0

type Exchange struct {
	BaseCurrency currency.Currency
	Engines      []engines.Name
	Timings      ExchangeTimings
}

type ExchangeTimings added in v0.26.0

type ExchangeTimings struct {
	// Hard timeout after which the search is forcefully stopped (even if the engines didn't respond).
	HardTimeout time.Duration
}

type ImageProxy

type ImageProxy struct {
	SecretKey string
	Timeout   time.Duration
}

type ReaderCache

type ReaderCache struct {
	// Can be "none", "redis" or "dynamodb".
	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"`
	// DynamoDB specific settings.
	DynamoDB DynamoDB `koanf:"dynamodb"`
}

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"`
	RExchange   ReaderExchange                   `koanf:"exchange"`
}

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

type ReaderExchange added in v0.26.0

type ReaderExchange struct {
	BaseCurrency string                          `koanf:"basecurrency"`
	REngines     map[string]ReaderExchangeEngine `koanf:"engines"`
	RTimings     ReaderExchangeTimings           `koanf:"timings"`
}

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

type ReaderExchangeEngine added in v0.26.0

type ReaderExchangeEngine struct {
	// If false, the engine will not be used.
	Enabled bool `koanf:"enabled"`
}

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

type ReaderExchangeTimings added in v0.26.0

type ReaderExchangeTimings struct {
	// Hard timeout after which the search is forcefully stopped (even if the engines didn't respond).
	HardTimeout string `koanf:"hardtimeout"`
}

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.

type ReaderImageProxy

type ReaderImageProxy struct {
	SecretKey string `koanf:"secretkey"`
	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 currencies in cache.
	// Setting this to 0 caches the currencies forever.
	Currencies string `koanf:"currencies"`
}

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 currencies in cache.
	// Setting this to 0 caches the currencies forever.
	Currencies time.Duration
}

Jump to

Keyboard shortcuts

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