diff --git a/go.mod b/go.mod index e2a7ed63790f1b81d1085be4de251a811e08de1b..3b6f909427368782d65a90c216216400dedf3e67 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/googollee/go-engine.io v1.4.3-0.20190924125625-798118fc0dd2 github.com/googollee/go-socket.io v1.4.3-0.20191204093753-683f8725b6d0 github.com/gorilla/websocket v1.4.1 - github.com/iotaledger/hive.go v0.0.0-20200222013046-8268a12f52cb + github.com/iotaledger/hive.go v0.0.0-20200225022819-32427644698a github.com/iotaledger/iota.go v1.0.0-beta.14 github.com/kr/pretty v0.2.0 // indirect github.com/kr/text v0.2.0 // indirect diff --git a/go.sum b/go.sum index becfd602b24ae7bc8c021386b77b8d4f79456390..ecf2a9879fb12370eb557926746b221e5d56c470 100644 --- a/go.sum +++ b/go.sum @@ -141,6 +141,10 @@ github.com/iotaledger/hive.go v0.0.0-20200219224037-2d5f5238c0de h1:J9G9YWM5q7r3 github.com/iotaledger/hive.go v0.0.0-20200219224037-2d5f5238c0de/go.mod h1:wj3bFHlcX0NiEOWu5+WOg/MI/5N7PKCFnyaziaylB64= github.com/iotaledger/hive.go v0.0.0-20200222013046-8268a12f52cb h1:lLObap03uuF0RPSGHflpzIZIdKz2robq/rqT3b1ghqU= github.com/iotaledger/hive.go v0.0.0-20200222013046-8268a12f52cb/go.mod h1:wj3bFHlcX0NiEOWu5+WOg/MI/5N7PKCFnyaziaylB64= +github.com/iotaledger/hive.go v0.0.0-20200225021953-8c07d94b7c38 h1:QsBAGr1fPwxrzvvRB2zy27gxDmeBhiWN87LD37jd0ZQ= +github.com/iotaledger/hive.go v0.0.0-20200225021953-8c07d94b7c38/go.mod h1:wj3bFHlcX0NiEOWu5+WOg/MI/5N7PKCFnyaziaylB64= +github.com/iotaledger/hive.go v0.0.0-20200225022819-32427644698a h1:ga4SOHLYzXNCC7qHxBN8lK4kng8Ffu2x2QB+yKolH2w= +github.com/iotaledger/hive.go v0.0.0-20200225022819-32427644698a/go.mod h1:wj3bFHlcX0NiEOWu5+WOg/MI/5N7PKCFnyaziaylB64= github.com/iotaledger/iota.go v1.0.0-beta.9/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= github.com/iotaledger/iota.go v1.0.0-beta.14 h1:Oeb28MfBuJEeXcGrLhTCJFtbsnc8y1u7xidsAmiOD5A= github.com/iotaledger/iota.go v1.0.0-beta.14/go.mod h1:F6WBmYd98mVjAmmPVYhnxg8NNIWCjjH8VWT9qvv3Rc8= diff --git a/main.go b/main.go index b0c2b7d383feca996145681ecf6db924542e1cd3..efcc34bcd33174023852c13f2730b12fa1263b4d 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,7 @@ import ( ) func main() { - cli.PrintVersion() + config.Init() go http.ListenAndServe("localhost:6061", nil) // pprof Server for Debbuging Mutexes diff --git a/plugins/banner/plugin.go b/plugins/banner/plugin.go index 3d06962807e50c8662c86f9b8545927ad0afabcb..b4e4b28487f9cfb48d08c2af61900beb539b2dc1 100644 --- a/plugins/banner/plugin.go +++ b/plugins/banner/plugin.go @@ -10,7 +10,7 @@ var PLUGIN = node.NewPlugin("Banner", node.Enabled, configure, run) const ( // AppVersion version number - AppVersion = "v0.1.1" + AppVersion = "v0.2.0" // AppName app code name AppName = "GoShimmer" diff --git a/plugins/cli/plugin.go b/plugins/cli/plugin.go index eab5b9b0eb6dfa79e459e528bfa88d48d2bc0b0c..da1b61411ee8b1b483fd4063f4da38e304daf98f 100644 --- a/plugins/cli/plugin.go +++ b/plugins/cli/plugin.go @@ -1,16 +1,19 @@ package cli import ( + "fmt" + "os" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/node" flag "github.com/spf13/pflag" + + "github.com/iotaledger/goshimmer/plugins/banner" ) var PLUGIN = node.NewPlugin("CLI", node.Enabled) -func onAddPlugin(name string, status int) { - AddPluginStatus(node.GetPluginIdentifier(name), status) -} +var version = flag.BoolP("version", "v", false, "Prints the GoShimmer version") func init() { for name, status := range node.GetPlugins() { @@ -20,4 +23,17 @@ func init() { node.Events.AddPlugin.Attach(events.NewClosure(onAddPlugin)) flag.Usage = printUsage + + PLUGIN.Events.Init.Attach(events.NewClosure(onInit)) +} + +func onAddPlugin(name string, status int) { + AddPluginStatus(node.GetPluginIdentifier(name), status) +} + +func onInit(*node.Plugin) { + if *version { + fmt.Println(banner.AppName + " " + banner.AppVersion) + os.Exit(0) + } } diff --git a/plugins/config/plugin.go b/plugins/config/plugin.go index 0bf459dbaaa14498e3ef22226a5487808a3cf296..1cd941232ced9cecbafd719f86209c47b46d747d 100644 --- a/plugins/config/plugin.go +++ b/plugins/config/plugin.go @@ -1,6 +1,7 @@ package config import ( + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/parameter" @@ -31,8 +32,8 @@ var ( } ) -func Load() { - // do nothing - the config get's initialized during init() +func Init() { + PLUGIN.Events.Init.Trigger(PLUGIN) } func init() { @@ -40,9 +41,11 @@ func init() { Node = viper.New() Node.SetDefault(logger.ViperKey, defaultLoggerConfig) - if err := fetch(false); err != nil { - panic(err) - } + PLUGIN.Events.Init.Attach(events.NewClosure(func(*node.Plugin) { + 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). @@ -50,6 +53,7 @@ func init() { // 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 { + flag.Parse() err := parameter.LoadConfigFile(Node, *configDirPath, *configName, true, true) if err != nil { return err diff --git a/plugins/logger/plugin.go b/plugins/logger/plugin.go index 79d30596e111f13e0ebb8ecf3a372833abd2f10b..d3f85693a0031a613811fe056ac13d560dbcbe2c 100644 --- a/plugins/logger/plugin.go +++ b/plugins/logger/plugin.go @@ -1,21 +1,23 @@ package logger import ( + "github.com/iotaledger/goshimmer/plugins/config" + "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/node" - - "github.com/iotaledger/goshimmer/plugins/config" ) // define the plugin as a placeholder, so the init methods get executed accordingly var PLUGIN = node.NewPlugin("Logger", node.Enabled) -func Load() { - // do nothing - the config get's initialized during init() +func Init() { + PLUGIN.Events.Init.Trigger(PLUGIN) } func init() { - if err := logger.InitGlobalLogger(config.Node); err != nil { - panic(err) - } + PLUGIN.Events.Init.Attach(events.NewClosure(func(*node.Plugin) { + if err := logger.InitGlobalLogger(config.Node); err != nil { + panic(err) + } + })) } diff --git a/tools/relay-checker/main.go b/tools/relay-checker/main.go index 7518c76b56f803726f22d8fb0421cb876decc268..8e98efcab1c082a4226dab42bef9c857f9370ab4 100644 --- a/tools/relay-checker/main.go +++ b/tools/relay-checker/main.go @@ -40,8 +40,8 @@ func testNodesGetTransactions(txnHash trinary.Hash) error { } func main() { - config.Load() - logger.Load() + config.Init() + logger.Init() InitConfig()