config

package
v0.0.0-...-28b05a4 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: GPL-2.0 Imports: 5 Imported by: 0

README

Package Config

This directory is for supporting the configuration functionalities.

Add New Configurations

Step 1: Specify a configuration struct anywhere like the struct below:

// P2pConfig is the configuration for libp2p-related instances
type P2pConfig struct {
    Addr      string `yaml:"addr"`      // libp2p listening address (default: 0.0.0.0)
    Port      int    `yaml:"port"`      // libp2p listening port
    GroupName string `yaml:"groupName"` // Name used for discovering nodes via mDNS
    PeerLimit int    `yaml:"peerLimit"` // Max number of peers this node can establish connection to
}

Requirements:

  1. This struct must be exported.
  2. All the fields in the struct must be exported.
  3. Use the yaml tag to specify the key for this config in the yml config file.

Step 2: Add this struct to the config struct:

// config is the configuration structure for the whole Openmesh Core project
type config struct {
    P2P P2pConfig `yaml:"p2p"`
}

Requirements:

  1. The field for this struct must be exported.
  2. Use the yaml tag to specify the key for this config in the yml config file.

Step 3: Add configurations in config.yml (default configuration file) or other customised configuration file.

p2p:
  # 0.0.0.0 = localhost
  addr: 0.0.0.0
  # 0 = random port
  port: 0
  groupName: xnode
  peerLimit: 50

Step 4: Retrieve your configuration value from the config.Config global variable:

limit := config.Config.P2P.PeerLimit

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Path string // Path to config file
	Name string // Name (without extension) of config file
)
View Source
var Config config

Config is a global variable that hold all the configurations need by the whole project NOTE: It must be initialised via ParseConfig() before use

Functions

func ParseConfig

func ParseConfig(configAtCompileTime string, useRuntimeConfigFile bool)

ParseConfig parses the yml configuration file and initialise the Config variable

func ParseFlags

func ParseFlags()

Types

type BFTConfig

type BFTConfig struct {
	HomeDir             string `yaml:"homeDir"`             // Path to CometBFT config
	MockTransactions    bool   `yaml:"mockTransactions"`    // Mock transacitons
	SkipSourceSelection bool   `yaml:"skipSourceSelection"` // Source field selection
}

BFTConfig is the configuration for using CometBFT

type CollectorConfig

type CollectorConfig struct {
	ApiKeys map[string]string `yaml:"apiKeys"` // API keys for each authenticated source
}

type DBConfig

type DBConfig struct {
	Username string `yaml:"username"` // Username for the specific database to be connected
	Password string `yaml:"password"` // Password for the specific database to be connected
	Port     int    `yaml:"port"`     // Database connection port
	DBName   string `yaml:"dbName"`   // Name for the database used
	URL      string `yaml:"URL"`      // Database connection URL
}

DBConfig is the configuration for database connection and operation

type ErrorLogConfig

type ErrorLogConfig struct {
	FileName   string `yaml:"fileName"`   // Name and path to the error log
	MaxSize    int    `yaml:"maxSize"`    // Megabytes
	MaxAge     int    `yaml:"maxAge"`     // Days
	MaxBackups int    `yaml:"maxBackups"` // How much old error log files to retain
	ToStderr   bool   `yaml:"toStderr"`   // Log to stderr (except file) or not
	ToFile     bool   `yaml:"toFile"`     // Log to file or not
}

type InfoLogConfig

type InfoLogConfig struct {
	FileName   string `yaml:"fileName"`   // Name and path to the info log
	MaxSize    int    `yaml:"maxSize"`    // Megabytes
	MaxAge     int    `yaml:"maxAge"`     // Days
	MaxBackups int    `yaml:"maxBackups"` // How much old info log files to retain
	ToStdout   bool   `yaml:"toStdout"`   // Log to stdout (except file) or not
	ToFile     bool   `yaml:"toFile"`     // Log to file or not
}

type LogConfig

type LogConfig struct {
	Development bool           `yaml:"development"`   // Development logger has DEBUG level and is more human-friendly
	Encoding    string         `yaml:"encoding"`      // Default: JSON for production
	InfoConfig  InfoLogConfig  `mapstructure:"info"`  // Sub-config for info-level logs
	ErrorConfig ErrorLogConfig `mapstructure:"error"` // Sub-config for error-level logs
}

LogConfig is the configuration for zap logger

type P2pConfig

type P2pConfig struct {
	Addr                      string `yaml:"addr"`                      // libp2p listening address (default: 0.0.0.0)
	Port                      int    `yaml:"port"`                      // libp2p listening port
	GroupName                 string `yaml:"groupName"`                 // Name used for discovering nodes via mDNS
	PeerLimit                 int    `yaml:"peerLimit"`                 // Max number of peers this node can establish connection to
	DebugAutoconnectMultiaddr string `yaml:"debugAutoconnectMultiaddr"` // Multiaddr of node to automatically connect to.
}

type Profiling

type Profiling struct {
	Enable     bool   `yaml:"enable"`
	EnableHttp bool   `yaml:"enableHttp"`
	FileName   string `yaml:"fileName"`
}

type TrConfig

type TrConfig struct {
	RpcAddress     string `yaml:"rpcAddress"`
	UnlimitedRPC   bool   `yaml:"unlimitedRPC"`
	EventSignature string `yaml:"eventSignature"`
	SearchLimit    int    `yaml:"searchLimit"`
	DeployBlock    int    `yaml:"DeployBlock"` // Corrected field name
	Confirmations  int    `yaml:"confirmations"`
	Timing         int    `yaml:"timing"` // Corrected field name
	IsTest         bool   `yaml:"istest"`
}

Jump to

Keyboard shortcuts

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