web.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package main
  5. import (
  6. "fmt"
  7. "net/http"
  8. "github.com/codegangsta/cli"
  9. "github.com/codegangsta/martini"
  10. "github.com/martini-contrib/render"
  11. "github.com/gogits/gogs/routers"
  12. "github.com/gogits/gogs/routers/user"
  13. "github.com/gogits/gogs/utils"
  14. "github.com/gogits/gogs/utils/log"
  15. )
  16. var CmdWeb = cli.Command{
  17. Name: "web",
  18. Usage: "just run",
  19. Description: `
  20. gogs web`,
  21. Action: runWeb,
  22. Flags: []cli.Flag{
  23. //cli.BoolFlag{"update, u", "update pakcage(s) and dependencies if any"},
  24. //cli.BoolFlag{"verbose, v", "show process details"},
  25. },
  26. }
  27. func runWeb(*cli.Context) {
  28. log.Info("%s %s", utils.Cfg.MustValue("", "APP_NAME"), APP_VER)
  29. m := martini.Classic()
  30. // Middleware.
  31. m.Use(render.Renderer())
  32. // Routers.
  33. m.Get("/", routers.Dashboard)
  34. m.Get("/user/signin", user.SignIn)
  35. m.Any("/user/signup", user.SignUp)
  36. listenAddr := fmt.Sprintf("%s:%s",
  37. utils.Cfg.MustValue("server", "HTTP_ADDR"),
  38. utils.Cfg.MustValue("server", "HTTP_PORT", "3000"))
  39. log.Info("Listen: %s", listenAddr)
  40. http.ListenAndServe(listenAddr, m)
  41. }