web.go 863 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package cmd
  2. import (
  3. "os"
  4. "time"
  5. "github.com/codegangsta/cli"
  6. "github.com/siddontang/go-log/log"
  7. "github.com/torkelo/grafana-pro/pkg/configuration"
  8. "github.com/torkelo/grafana-pro/pkg/routes"
  9. "github.com/torkelo/grafana-pro/pkg/server"
  10. )
  11. var CmdWeb = cli.Command{
  12. Name: "web",
  13. Usage: "Start Grafana Pro web server",
  14. Description: `Start Grafana Pro server`,
  15. Action: runWeb,
  16. Flags: []cli.Flag{},
  17. }
  18. func runWeb(*cli.Context) {
  19. routes.GlobalInit()
  20. port := os.Getenv("PORT")
  21. if port == "" {
  22. port = "3838"
  23. }
  24. log.Info("Starting Grafana-Pro v.1-alpha")
  25. cfg := configuration.NewCfg(port)
  26. server, err := server.NewServer(cfg)
  27. if err != nil {
  28. time.Sleep(time.Second)
  29. panic(err)
  30. }
  31. err = server.ListenAndServe()
  32. if err != nil {
  33. log.Error("ListenAndServe failed: ", err)
  34. }
  35. time.Sleep(time.Millisecond * 2000)
  36. }