From 2111bb9cf055eecf6042c4dde58bc9a51e93e6cb Mon Sep 17 00:00:00 2001 From: Hans Moog <hm@mkjc.net> Date: Wed, 19 Feb 2020 01:04:45 +0100 Subject: [PATCH] Feat: added a banner module for the cli interface --- main.go | 2 ++ plugins/autopeering/autopeering.go | 4 ++-- plugins/banner/plugin.go | 35 ++++++++++++++++++++++++++++++ plugins/cli/plugin.go | 29 ++----------------------- plugins/gossip/gossip.go | 4 ++-- 5 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 plugins/banner/plugin.go diff --git a/main.go b/main.go index bf91966f..352f263f 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "github.com/iotaledger/goshimmer/plugins/analysis" "github.com/iotaledger/goshimmer/plugins/autopeering" + "github.com/iotaledger/goshimmer/plugins/banner" "github.com/iotaledger/goshimmer/plugins/cli" "github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/goshimmer/plugins/gossip" @@ -27,6 +28,7 @@ func main() { node.Run( node.Plugins( + banner.PLUGIN, config.PLUGIN, logger.PLUGIN, cli.PLUGIN, diff --git a/plugins/autopeering/autopeering.go b/plugins/autopeering/autopeering.go index c02b8bf8..390bc68e 100644 --- a/plugins/autopeering/autopeering.go +++ b/plugins/autopeering/autopeering.go @@ -18,7 +18,7 @@ import ( "github.com/iotaledger/goshimmer/packages/netutil" "github.com/iotaledger/goshimmer/plugins/autopeering/local" - "github.com/iotaledger/goshimmer/plugins/cli" + "github.com/iotaledger/goshimmer/plugins/banner" "github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/goshimmer/plugins/gossip" ) @@ -172,6 +172,6 @@ func checkConnection(localAddr *net.UDPAddr, self *peer.Peer) { if err != nil { log.Errorf("Error testing service: %s", err) log.Panicf("Please check that %s is publicly reachable at %s/%s", - cli.AppName, peering.String(), peering.Network()) + banner.AppName, peering.String(), peering.Network()) } } diff --git a/plugins/banner/plugin.go b/plugins/banner/plugin.go new file mode 100644 index 00000000..3d069628 --- /dev/null +++ b/plugins/banner/plugin.go @@ -0,0 +1,35 @@ +package banner + +import ( + "fmt" + + "github.com/iotaledger/hive.go/node" +) + +var PLUGIN = node.NewPlugin("Banner", node.Enabled, configure, run) + +const ( + // AppVersion version number + AppVersion = "v0.1.1" + + // AppName app code name + AppName = "GoShimmer" +) + +func configure(ctx *node.Plugin) { + fmt.Printf(` + _____ ____ _____ _ _ _____ __ __ __ __ ______ _____ + / ____|/ __ \ / ____| | | |_ _| \/ | \/ | ____| __ \ + | | __| | | | (___ | |__| | | | | \ / | \ / | |__ | |__) | + | | |_ | | | |\___ \| __ | | | | |\/| | |\/| | __| | _ / + | |__| | |__| |____) | | | |_| |_| | | | | | | |____| | \ \ + \_____|\____/|_____/|_| |_|_____|_| |_|_| |_|______|_| \_\ + %s +`, AppVersion) + fmt.Println() + + ctx.Node.Logger.Infof("GoShimmer version %s ...", AppVersion) + ctx.Node.Logger.Info("Loading plugins ...") +} + +func run(ctx *node.Plugin) {} diff --git a/plugins/cli/plugin.go b/plugins/cli/plugin.go index 47b250ae..e85619d6 100644 --- a/plugins/cli/plugin.go +++ b/plugins/cli/plugin.go @@ -1,21 +1,12 @@ package cli import ( - "fmt" - "github.com/iotaledger/hive.go/events" "github.com/iotaledger/hive.go/node" flag "github.com/spf13/pflag" ) -const ( - // AppVersion version number - AppVersion = "v0.1.1" - // AppName app code name - AppName = "GoShimmer" -) - -var PLUGIN = node.NewPlugin("CLI", node.Enabled, configure, run) +var PLUGIN = node.NewPlugin("CLI", node.Enabled, run) func onAddPlugin(name string, status int) { AddPluginStatus(node.GetPluginIdentifier(name), status) @@ -31,22 +22,6 @@ func init() { flag.Usage = printUsage } -func configure(ctx *node.Plugin) { - fmt.Printf(` - _____ ____ _____ _ _ _____ __ __ __ __ ______ _____ - / ____|/ __ \ / ____| | | |_ _| \/ | \/ | ____| __ \ - | | __| | | | (___ | |__| | | | | \ / | \ / | |__ | |__) | - | | |_ | | | |\___ \| __ | | | | |\/| | |\/| | __| | _ / - | |__| | |__| |____) | | | |_| |_| | | | | | | |____| | \ \ - \_____|\____/|_____/|_| |_|_____|_| |_|_| |_|______|_| \_\ - %s -`, AppVersion) - fmt.Println() - - ctx.Node.Logger.Infof("GoShimmer version %s ...", AppVersion) - ctx.Node.Logger.Info("Loading plugins ...") -} - func run(ctx *node.Plugin) { - // do nothing; everything is handled in the configure step + // do nothing; everything is handled in the init method } diff --git a/plugins/gossip/gossip.go b/plugins/gossip/gossip.go index 3697608d..ab00f21d 100644 --- a/plugins/gossip/gossip.go +++ b/plugins/gossip/gossip.go @@ -14,7 +14,7 @@ import ( gp "github.com/iotaledger/goshimmer/packages/gossip" "github.com/iotaledger/goshimmer/packages/gossip/server" "github.com/iotaledger/goshimmer/plugins/autopeering/local" - "github.com/iotaledger/goshimmer/plugins/cli" + "github.com/iotaledger/goshimmer/plugins/banner" "github.com/iotaledger/goshimmer/plugins/config" "github.com/iotaledger/goshimmer/plugins/tangle" ) @@ -99,7 +99,7 @@ func checkConnection(srv *server.TCP, self *peer.Peer) { log.Errorf("Error testing: %s", err) addr := self.Services().Get(service.GossipKey) log.Panicf("Please check that %s is publicly reachable at %s/%s", - cli.AppName, addr.String(), addr.Network()) + banner.AppName, addr.String(), addr.Network()) } _ = conn.Close() wg.Wait() -- GitLab