web.go 1.4 KB

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