Skip to content
Snippets Groups Projects
Select Git revision
  • f357ee39a5151c4f7806c718c94b1589047a919c
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

plugin.go

Blame
  • plugin.go 1.94 KiB
    package config
    
    import (
    	"github.com/iotaledger/hive.go/logger"
    	"github.com/iotaledger/hive.go/node"
    	"github.com/iotaledger/hive.go/parameter"
    	"github.com/spf13/viper"
    
    	flag "github.com/spf13/pflag"
    )
    
    var (
    	// define the plugin as a placeholder, so the init methods get executed accordingly
    	PLUGIN = node.NewPlugin("Config", node.Enabled)
    
    	// flags<
    	configName    = flag.StringP("config", "c", "config", "Filename of the config file without the file extension")
    	configDirPath = flag.StringP("config-dir", "d", ".", "Path to the directory containing the config file")
    
    	// viper
    	Node *viper.Viper
    
    	// logger
    	defaultLoggerConfig = logger.Config{
    		Level:             "info",
    		DisableCaller:     false,
    		DisableStacktrace: false,
    		Encoding:          "console",
    		OutputPaths:       []string{"goshimmer.log"},
    		DisableEvents:     false,
    	}
    )
    
    func Load() {
    	// do nothing - the config get's initialized during init()
    }
    
    func init() {
    	// set the default logger config
    	Node = viper.New()
    	Node.SetDefault(logger.ViperKey, defaultLoggerConfig)
    
    	if err := fetch(false); err != nil {
    		panic(err)
    	}
    }
    
    // fetch fetches config values from a dir defined via CLI flag --config-dir (or the current working dir if not set).
    //
    // It automatically reads in a single config file starting with "config" (can be changed via the --config CLI flag)
    // and ending with: .json, .toml, .yaml or .yml (in this sequence).
    func fetch(printConfig bool, ignoreSettingsAtPrint ...[]string) error {
    	err := parameter.LoadConfigFile(Node, *configDirPath, *configName, true, true)
    	if err != nil {
    		return err
    	}
    
    	if printConfig {
    		parameter.PrintConfig(Node, ignoreSettingsAtPrint...)
    	}
    
    	for _, pluginName := range Node.GetStringSlice(node.CFG_DISABLE_PLUGINS) {
    		node.DisabledPlugins[node.GetPluginIdentifier(pluginName)] = true
    	}
    	for _, pluginName := range Node.GetStringSlice(node.CFG_ENABLE_PLUGINS) {
    		node.EnabledPlugins[node.GetPluginIdentifier(pluginName)] = true
    	}
    
    	return nil
    }