main.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "os"
  6. "os/signal"
  7. "syscall"
  8. "time"
  9. )
  10. var (
  11. //Global variables
  12. stopchan chan bool
  13. //Runtime flags
  14. benchmarkWebserverListeningPort int
  15. )
  16. func init() {
  17. flag.IntVar(&benchmarkWebserverListeningPort, "port", 8123, "Port to listen on")
  18. flag.Parse()
  19. }
  20. /* SIGTERM handler, do shutdown sequences before closing */
  21. func SetupCloseHandler() {
  22. c := make(chan os.Signal, 2)
  23. signal.Notify(c, os.Interrupt, syscall.SIGTERM)
  24. go func() {
  25. <-c
  26. //Stop all request loops
  27. fmt.Println("Stopping request generators")
  28. if stopchan != nil {
  29. stopchan <- true
  30. }
  31. // Wait for all goroutines to finish
  32. time.Sleep(1 * time.Second)
  33. os.Exit(0)
  34. }()
  35. }
  36. func main() {
  37. //Setup the SIGTERM handler
  38. SetupCloseHandler()
  39. //Start the web server
  40. fmt.Println("Starting web server on port", benchmarkWebserverListeningPort)
  41. fmt.Println("In Zoraxy, point your test proxy rule to this server at the given port")
  42. startWebServer()
  43. select {}
  44. }