Skip to content
Snippets Groups Projects
Select Git revision
  • e53cfef013d2cb973b8a90587f611f87278ec438
  • 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.01 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"
    )
    
    var PLUGIN = node.NewPlugin("WebAPI", node.Enabled, configure, run)
    var log = logger.NewLogger("WebAPI")
    
    var Server = echo.New()
    
    func configure(plugin *node.Plugin) {
    	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(":8080"); 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())
    		}
    	})
    }