config

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateConfig

func ValidateConfig(cfg *Config) error

Types

type AlloraAPIConfig added in v0.1.14

type AlloraAPIConfig struct {
	URL          string              `mapstructure:"url" validate:"required,url"`
	APIKey       string              `mapstructure:"api_key"`
	TopicMetrics []TopicMetricConfig `mapstructure:"topic_metrics" validate:"dive"`
}

type AlloraConfig

type AlloraConfig struct {
	RPC     string        `mapstructure:"rpc" validate:"required,url"` // RPC URL of the Allora chain
	Timeout time.Duration `mapstructure:"timeout" validate:"required"` // Timeout in seconds for RPC requests
}

type Config

type Config struct {
	Database              DatabaseConfig              `mapstructure:"database" validate:"required"`
	Kafka                 KafkaConfig                 `mapstructure:"kafka" validate:"required"`
	Allora                AlloraConfig                `mapstructure:"allora" validate:"required"`
	KafkaTopicRouter      []KafkaTopicRouterConfig    `mapstructure:"kafka_topic_router" validate:"required,gt=0,dive"`
	FilterEvent           FilterEventConfig           `mapstructure:"filter_event" validate:"required"`
	FilterTransaction     FilterTransactionConfig     `mapstructure:"filter_transaction" validate:"required"`
	Log                   LogConfig                   `mapstructure:"log" validate:"required"`
	Producer              ProducerConfig              `mapstructure:"producer" validate:"required"`
	QueryProducer         QueryProducerConfig         `mapstructure:"query_producer" validate:"required"`
	QueryResultRepository QueryResultRepositoryConfig `mapstructure:"query_result_repository" validate:"required"`
	AlloraAPI             AlloraAPIConfig             `mapstructure:"allora_api" validate:"required"`
}

type DatabaseConfig

type DatabaseConfig struct {
	URL string `mapstructure:"url" validate:"required,url"` // URL of the database
}

type FilterEventConfig

type FilterEventConfig struct {
	Types []string `mapstructure:"types" validate:"required,gt=0,dive,min=1"` // Types of events to filter
}

type FilterTransactionConfig

type FilterTransactionConfig struct {
	Types []string `mapstructure:"types" validate:"gt=0,dive,min=1"` // Types of transactions to filter
}

type KafkaConfig

type KafkaConfig struct {
	Seeds    []string `mapstructure:"seeds" validate:"required,gt=0,dive,hostname_port"` // Kafka seeds
	User     string   `mapstructure:"user" validate:"required,min=1"`                    // Kafka user
	Password string   `mapstructure:"password" validate:"required,min=1"`                // Kafka password
}

type KafkaTopicRouterConfig

type KafkaTopicRouterConfig struct {
	Name  string   `mapstructure:"name" validate:"required"`                  // Name of the Kafka topic
	Types []string `mapstructure:"types" validate:"required,gt=0,dive,min=1"` // Types of messages to route to the topic
}

type Loader

type Loader interface {
	AddConfigPath(path string)
	SetConfigName(name string)
	SetConfigType(configType string)
	SetEnvPrefix(prefix string)
	SetEnvKeyReplacer(replacer *strings.Replacer)
	AutomaticEnv()
	ReadInConfig() error
	ConfigFileUsed() string
	Unmarshal(rawVal interface{}) error
	BindEnv(key string, envVar string) error
}

ConfigLoader defines the methods required for configuration loading. This interface abstracts the Viper library to facilitate unit testing.

func NewViperAdapter

func NewViperAdapter() Loader

NewViperAdapter creates a new instance of ViperAdapter.

type LogConfig

type LogConfig struct {
	Level int8 `mapstructure:"level" validate:"gte=-1,lte=7"` // Log level
}

type ProducerConfig

type ProducerConfig struct {
	BlockRefreshInterval time.Duration `mapstructure:"block_refresh_interval" validate:"required"` // Block refresh interval
	RateLimitInterval    time.Duration `mapstructure:"rate_limit_interval" validate:"required"`    // Rate limit interval
	NumWorkers           int           `mapstructure:"num_workers" validate:"required,gt=0"`       // Number of workers to process blocks and block results
}

type Provider

type Provider interface {
	InitConfig() (Config, error)
}

func NewProvider

func NewProvider(loader Loader) Provider

type QueryProducerConfig added in v0.1.10

type QueryProducerConfig struct {
	EpochInterval     time.Duration `mapstructure:"epoch_interval" validate:"required"`      // Epoch interval
	RateLimitInterval time.Duration `mapstructure:"rate_limit_interval" validate:"required"` // Rate limit interval
}

type QueryResultRepositoryConfig added in v0.1.10

type QueryResultRepositoryConfig struct {
	URL string `mapstructure:"url" validate:"required,url"` // URL of the query result repository
}

type TopicMetricConfig added in v0.1.14

type TopicMetricConfig struct {
	TopicID      uint64 `mapstructure:"topic_id" validate:"required"`
	Type         string `mapstructure:"type" validate:"required"`
	Ticker       string `mapstructure:"ticker" validate:"required"`
	TimeInterval string `mapstructure:"time_interval" validate:"required"`
}

type ViperAdapter

type ViperAdapter struct {
	*viper.Viper
}

ViperAdapter is a concrete implementation of ConfigLoader using Viper.

func (*ViperAdapter) AddConfigPath

func (v *ViperAdapter) AddConfigPath(path string)

AddConfigPath adds a path for Viper to search for the configuration file.

func (*ViperAdapter) AutomaticEnv

func (v *ViperAdapter) AutomaticEnv()

AutomaticEnv enables Viper to automatically read configuration from environment variables.

func (*ViperAdapter) BindEnv added in v0.1.14

func (v *ViperAdapter) BindEnv(key string, envVar string) error

BindEnv binds a configuration key to an environment variable.

func (*ViperAdapter) ConfigFileUsed

func (v *ViperAdapter) ConfigFileUsed() string

ConfigFileUsed returns the file path of the configuration file used.

func (*ViperAdapter) ReadInConfig

func (v *ViperAdapter) ReadInConfig() error

ReadInConfig reads the configuration from the specified file.

func (*ViperAdapter) SetConfigName

func (v *ViperAdapter) SetConfigName(name string)

SetConfigName sets the name of the configuration file without the extension.

func (*ViperAdapter) SetConfigType

func (v *ViperAdapter) SetConfigType(configType string)

SetConfigType sets the type of the configuration file (e.g., "yaml").

func (*ViperAdapter) SetEnvKeyReplacer

func (v *ViperAdapter) SetEnvKeyReplacer(replacer *strings.Replacer)

SetEnvKeyReplacer sets the key replacer for environment variables.

func (*ViperAdapter) SetEnvPrefix

func (v *ViperAdapter) SetEnvPrefix(prefix string)

SetEnvPrefix sets the prefix for environment variables.

func (*ViperAdapter) Unmarshal

func (v *ViperAdapter) Unmarshal(rawVal interface{}) error

Unmarshal unmarshals the configuration into the provided structure.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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