config

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 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 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"`
}

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
}

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 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) 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