config

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2019 License: MIT Imports: 8 Imported by: 0

README

Config package is here to provide a prioritized configuration registry for all subsystems/packages. Based on github.com/spf13/viper it provides:

  • A separate package to expose by value all loaded configs to any node package

    • No cyclic dependency issues
    • No config changes after the initial loading by main pkg
  • A prioritized registry for different config sources (flags, config file, env)

  • Support for a minimal config language (TOML)

  • Support for other config formats like JSON, YAML, HCL

    • *.json, *.toml, *.yaml, *.yml, *.properties, *.props, *.prop, *.hcl
  • Live-watching and re-reading of config files

  • Unmarshal-to-structs for better code readability and easier maintenance

  • config examples - samples/default.dusk.toml

  • Multiple config file searchPaths

    • current working directory
    • $HOME/.dusk/
  • Remote Key/Value Store (not yet in-use)

  • List of general constants defined in config/consts.go

Example usage:


# Try to load a config file from any of the searchPaths
# and overwrite general.network setting
user$ ./testnet --general.network=testnet

# with shorthand letter
user$ ./testnet -n=testnet

# Load a specified config file and overwrite logger.level
# config file name can be in form of dusk.toml, dusk.json, dusk.yaml, dusk.tf
user$ ./testnet --config=./pkg/config/default.dusk.toml --logger.level=error

# Load config file found in $searchPaths and overwrite general.network value
user$ DUSK_GENERAL_NETWORK=mainnet; ./testnet

# Load config where a file config value is overwritten by both ENV var and CLI flag but CLI flag has higher priority
user$ DUSK_LOGGER_LEVEL=WARN; ./testnet --logger.level=error

# with shorthand letter
user$ ./testnet -l=error

More detailed and up-to-date examples about supported flags, and ENV vars can be found in loader_test.go

Viper

Viper is a prioritized configuration registry. It maintains a set of configuration sources, fetches values to populate those, and provides them according to the source's priority.

The priority of the sources is the following:
1. overrides
2. flags
3. env. variables
4. config file
5. key/value store
6. defaults

Documentation

Index

Constants

View Source
const (
	// GeneratorReward is the amount of Block generator default reward
	// TODO: TBD
	GeneratorReward = 50 * DUSK

	// ConsensusTimeOut is the time out for consensus step timers.
	ConsensusTimeOut = 5 * time.Second

	// DUSK is one whole unit of DUSK.
	DUSK = uint64(100000000)

	MinFee = int64(100)

	// GenesisBlockBlob represents the genesis block bytes in hexadecimal format
	// It's recommended to be regenerated with generation.GenerateGensisBlock() API
	TestNetGenesisBlob = "" /* 31558-byte string literal not displayed */
)

A signle point of constants definition

Variables

This section is empty.

Functions

func DecodeGenesis

func DecodeGenesis() *block.Block

func Load

func Load() error

Load makes an attempt to read and unmershal any configs from flag, env and dusk config file.

It uses the following precedence order. Each item takes precedence over the item below it:

  • flag
  • env
  • config
  • key/value store (not used yet)
  • default

Dusk configuration file can be in form of TOML, JSON, YAML, HCL or Java properties config files

func Mock

func Mock(m *Registry)

Mock should be used only in test packages. It could be useful when a unit test needs to be rerun with configs different from the default ones.

Types

type Registry

type Registry struct {
	UsedConfigFile string

	// All configuration groups
	General     generalConfiguration
	Database    databaseConfiguration
	Wallet      walletConfiguration
	Network     networkConfiguration
	Logger      loggerConfiguration
	Prof        profConfiguration
	RPC         rpcConfiguration
	Performance performanceConfiguration
	Mempool     mempoolConfiguration
}

Registry stores all loaded configurations according to the config order NB It should be cheap to be copied by value

func Get

func Get() Registry

Get returns registry by value in order to avoid further modifications after initial configuration loading

Jump to

Keyboard shortcuts

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