No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.go 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package main
  2. import (
  3. "flag"
  4. "log"
  5. "math/rand"
  6. "net/http"
  7. _ "net/http/pprof"
  8. "os"
  9. "runtime/pprof"
  10. "time"
  11. "hackerbots.us/server"
  12. )
  13. var addr = flag.String("addr", ":8666", "http service address")
  14. var profile = flag.String("pprof", "", "if specified will run with pprof")
  15. var mprofile = flag.String("mprof", "", "if specified will dump a memory profile")
  16. var netprofile = flag.Bool("netprof", false, "if specified will run with net/http/pprof on :8667")
  17. var verbose = flag.Bool("verbose", false, "")
  18. var config = flag.String("config", "~/.config/hackerbots/server.json", "location of config file")
  19. func main() {
  20. log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
  21. log.Printf("Starting Server...")
  22. var err error
  23. rand.Seed(time.Now().UnixNano())
  24. flag.Parse()
  25. if *profile != "" {
  26. f, err := os.Create(*profile)
  27. if err != nil {
  28. log.Fatal(err)
  29. }
  30. pprof.StartCPUProfile(f)
  31. }
  32. if *netprofile {
  33. go func() {
  34. log.Println(http.ListenAndServe("localhost:8667", nil))
  35. }()
  36. log.Println("serving profile info at http://localhost:8667/debug/pprof/")
  37. }
  38. conf, err := server.LoadConfig(*config)
  39. if err != nil {
  40. log.Fatal(err)
  41. }
  42. c := server.NewController(conf, *mprofile, *profile, os.Getenv("STATIC"))
  43. err = http.ListenAndServe(*addr, c)
  44. if err != nil {
  45. log.Fatal("unable to start server")
  46. }
  47. }