Skip to content
Snippets Groups Projects
Select Git revision
  • 4702cc222e8525581df5e71e7f11bae72b5db4b4
  • 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

webapi.go

Blame
  • webapi.go 880 B
    package spammer
    
    import (
    	"net/http"
    
    	"github.com/labstack/echo"
    )
    
    func handleRequest(c echo.Context) error {
    	var request Request
    	if err := c.Bind(&request); err != nil {
    		return c.JSON(http.StatusBadRequest, Response{Error: err.Error()})
    	}
    
    	switch request.Cmd {
    	case "start":
    		if request.Tps == 0 {
    			request.Tps = 1
    		}
    
    		transactionSpammer.Shutdown()
    		transactionSpammer.Start(request.Tps)
    		return c.JSON(http.StatusOK, Response{Message: "started spamming transactions"})
    	case "stop":
    		transactionSpammer.Shutdown()
    		return c.JSON(http.StatusOK, Response{Message: "stopped spamming transactions"})
    	default:
    		return c.JSON(http.StatusBadRequest, Response{Error: "invalid cmd in request"})
    	}
    }
    
    type Response struct {
    	Message string `json:"message"`
    	Error   string `json:"error"`
    }
    
    type Request struct {
    	Cmd string `json:"cmd"`
    	Tps int    `json:"tps"`
    }