-
Hans Moog authored
* Feat: started to merge changes * Refactor: moved parameter package to be a plugin (same with logger) * Feat: first compiling version of new ontologoies merge * Feat: ported additional plugins * Feat: transaction get solid now * Refactor: reverted some previous changes from debugging * Feat: added a banner module for the cli interface * Feat: added a plugin for the port checks * Feat: fixed some bugs * Refactor: reverted some changes * Feat: reworked TransactionParser to use Errors * Feat: TransactionParser uses Peer * Feat: started to rework broadCastData webapi call * Feat: refactored some plugins * Fix: fixed test of tangle * Refactor: changed tangle package in graph plugin * Refactor: uncommented broken code * Fix: fixed broken method signature in gossip test * Feat: started adding value tangle * Feat: adjusted to new hive.go * Feat: upgraded hive.go * Clean up PortCheck plugin and make it standalone #259 (#271) Co-authored-by:
Hans Moog <hm@mkjc.net> Co-authored-by:
Jonas Theis <mail@jonastheis.de>
Hans Moog authored* Feat: started to merge changes * Refactor: moved parameter package to be a plugin (same with logger) * Feat: first compiling version of new ontologoies merge * Feat: ported additional plugins * Feat: transaction get solid now * Refactor: reverted some previous changes from debugging * Feat: added a banner module for the cli interface * Feat: added a plugin for the port checks * Feat: fixed some bugs * Refactor: reverted some changes * Feat: reworked TransactionParser to use Errors * Feat: TransactionParser uses Peer * Feat: started to rework broadCastData webapi call * Feat: refactored some plugins * Fix: fixed test of tangle * Refactor: changed tangle package in graph plugin * Refactor: uncommented broken code * Fix: fixed broken method signature in gossip test * Feat: started adding value tangle * Feat: adjusted to new hive.go * Feat: upgraded hive.go * Clean up PortCheck plugin and make it standalone #259 (#271) Co-authored-by:
Hans Moog <hm@mkjc.net> Co-authored-by:
Jonas Theis <mail@jonastheis.de>
plugin.go 1.19 KiB
package webapi
import (
"context"
"time"
"github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node"
"github.com/labstack/echo"
"github.com/iotaledger/goshimmer/packages/shutdown"
"github.com/iotaledger/goshimmer/plugins/config"
)
var PLUGIN = node.NewPlugin("WebAPI", node.Enabled, configure, run)
var log *logger.Logger
var Server = echo.New()
func configure(plugin *node.Plugin) {
log = logger.NewLogger("WebAPI")
Server.HideBanner = true
Server.HidePort = true
Server.GET("/", IndexRequest)
}
func run(plugin *node.Plugin) {
log.Info("Starting Web Server ...")
daemon.BackgroundWorker("WebAPI Server", func(shutdownSignal <-chan struct{}) {
log.Info("Starting Web Server ... done")
go func() {
if err := Server.Start(config.Node.GetString(BIND_ADDRESS)); err != nil {
log.Info("Stopping Web Server ... done")
}
}()
<-shutdownSignal
log.Info("Stopping Web Server ...")
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
if err := Server.Shutdown(ctx); err != nil {
log.Errorf("Couldn't stop server cleanly: %s", err.Error())
}
}, shutdown.ShutdownPriorityWebAPI)
}