web.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. "html/template"
  8. "net/http"
  9. "github.com/codegangsta/cli"
  10. "github.com/codegangsta/martini"
  11. "github.com/martini-contrib/render"
  12. "github.com/gogits/gogs/routers"
  13. "github.com/gogits/gogs/routers/repo"
  14. "github.com/gogits/gogs/routers/user"
  15. "github.com/gogits/gogs/utils"
  16. "github.com/gogits/gogs/utils/log"
  17. )
  18. var CmdWeb = cli.Command{
  19. Name: "web",
  20. Usage: "just run",
  21. Description: `
  22. gogs web`,
  23. Action: runWeb,
  24. Flags: []cli.Flag{
  25. //cli.BoolFlag{"update, u", "update pakcage(s) and dependencies if any"},
  26. //cli.BoolFlag{"verbose, v", "show process details"},
  27. },
  28. }
  29. var AppHelpers template.FuncMap = map[string]interface{}{
  30. "AppName": func() string {
  31. return utils.Cfg.MustValue("", "APP_NAME")
  32. },
  33. }
  34. func runWeb(*cli.Context) {
  35. log.Info("%s %s", utils.Cfg.MustValue("", "APP_NAME"), APP_VER)
  36. m := martini.Classic()
  37. // Middleware.
  38. m.Use(render.Renderer(render.Options{Funcs: []template.FuncMap{AppHelpers}}))
  39. // Routers.
  40. m.Get("/", routers.Dashboard)
  41. m.Any("/login", user.SignIn)
  42. m.Any("/user/signin", user.SignIn)
  43. m.Any("/sign-up", user.SignUp)
  44. m.Any("/user/signup", user.SignUp)
  45. m.Get("/user/profile", user.Profile) // should be /username
  46. m.Any("/user/delete", user.Delete)
  47. m.Any("/user/publickey/add", user.AddPublicKey)
  48. m.Any("/repo/create", repo.Create)
  49. m.Any("/repo/delete", repo.Delete)
  50. listenAddr := fmt.Sprintf("%s:%s",
  51. utils.Cfg.MustValue("server", "HTTP_ADDR"),
  52. utils.Cfg.MustValue("server", "HTTP_PORT", "3000"))
  53. log.Info("Listen: %s", listenAddr)
  54. http.ListenAndServe(listenAddr, m)
  55. }