From c9c372b1a529c8c73962a468a7379e63f6a05a74 Mon Sep 17 00:00:00 2001 From: Hans Moog <hm@mkjc.net> Date: Fri, 29 Mar 2019 07:37:20 +0100 Subject: [PATCH] Feat: added option to disable plugins + control log level --- packages/node/node.go | 26 ++++++++++++++++++++------ packages/node/parameters.go | 8 ++++++++ 2 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 packages/node/parameters.go diff --git a/packages/node/node.go b/packages/node/node.go index 4f74e652..bbbf7f85 100644 --- a/packages/node/node.go +++ b/packages/node/node.go @@ -3,6 +3,7 @@ package node import ( "fmt" "github.com/iotaledger/goshimmer/packages/daemon" + "strings" "sync" ) @@ -13,7 +14,13 @@ type Node struct { logLevel int } +var disabledPlugins = make(map[string]bool) + func Load(plugins ...*Plugin) *Node { + for _, disabledPlugin := range strings.Fields(*DISABLE_PLUGINS.Value) { + disabledPlugins[strings.ToLower(disabledPlugin)] = true + } + fmt.Println(" _____ _ _ ________ ______ ___ ___________ ") fmt.Println(" / ___| | | |_ _| \\/ || \\/ || ___| ___ \\") fmt.Println(" \\ `--.| |_| | | | | . . || . . || |__ | |_/ /") @@ -23,7 +30,7 @@ func Load(plugins ...*Plugin) *Node { fmt.Println() node := &Node{ - logLevel: LOG_LEVEL_INFO, + logLevel: *LOG_LEVEL.Value, loggers: make([]*Logger, 0), wg: &sync.WaitGroup{}, loadedPlugins: make([]*Plugin, 0), @@ -91,16 +98,23 @@ func (node *Node) Load(plugins ...*Plugin) { if len(plugins) >= 1 { for _, plugin := range plugins { - plugin.wg = node.wg - plugin.Node = node + fmt.Println(*DISABLE_PLUGINS.Value) + fmt.Println(disabledPlugins) + fmt.Println(strings.ToLower(strings.Replace(plugin.Name, " ", "", -1))) + if _, exists := disabledPlugins[strings.ToLower(strings.Replace(plugin.Name, " ", "", -1))]; !exists { + plugin.wg = node.wg + plugin.Node = node - plugin.Events.Configure.Trigger(plugin) + plugin.Events.Configure.Trigger(plugin) - node.LogInfo("Node", "Loading Plugin: "+plugin.Name+" ... done") + node.LogInfo("Node", "Loading Plugin: " + plugin.Name + " ... done") + + node.loadedPlugins = append(node.loadedPlugins, plugin) + } } } - node.loadedPlugins = append(node.loadedPlugins, plugins...) + //node.loadedPlugins = append(node.loadedPlugins, plugins...) } func (node *Node) Run() { diff --git a/packages/node/parameters.go b/packages/node/parameters.go new file mode 100644 index 00000000..9cf6276e --- /dev/null +++ b/packages/node/parameters.go @@ -0,0 +1,8 @@ +package node + +import "github.com/iotaledger/goshimmer/packages/parameter" + +var ( + LOG_LEVEL = parameter.AddInt("NODE/LOG_LEVEL", LOG_LEVEL_SUCCESS, "controls the log types that are shown") + DISABLE_PLUGINS = parameter.AddString("NODE/DISABLE_PLUGINS", "", "a list of plugins that shall be disabled") +) -- GitLab