web.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  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 cmd
  5. import (
  6. "crypto/tls"
  7. "fmt"
  8. "html/template"
  9. "io/ioutil"
  10. "net/http"
  11. "net/http/fcgi"
  12. "os"
  13. "path"
  14. "strings"
  15. "github.com/Unknwon/macaron"
  16. "github.com/codegangsta/cli"
  17. "github.com/macaron-contrib/binding"
  18. "github.com/macaron-contrib/cache"
  19. "github.com/macaron-contrib/captcha"
  20. "github.com/macaron-contrib/csrf"
  21. "github.com/macaron-contrib/i18n"
  22. "github.com/macaron-contrib/oauth2"
  23. "github.com/macaron-contrib/session"
  24. "github.com/macaron-contrib/toolbox"
  25. "gopkg.in/ini.v1"
  26. api "github.com/gogits/go-gogs-client"
  27. "github.com/gogits/gogs/models"
  28. "github.com/gogits/gogs/modules/auth"
  29. "github.com/gogits/gogs/modules/auth/apiv1"
  30. "github.com/gogits/gogs/modules/avatar"
  31. "github.com/gogits/gogs/modules/base"
  32. "github.com/gogits/gogs/modules/git"
  33. "github.com/gogits/gogs/modules/log"
  34. "github.com/gogits/gogs/modules/middleware"
  35. "github.com/gogits/gogs/modules/setting"
  36. "github.com/gogits/gogs/routers"
  37. "github.com/gogits/gogs/routers/admin"
  38. "github.com/gogits/gogs/routers/api/v1"
  39. "github.com/gogits/gogs/routers/dev"
  40. "github.com/gogits/gogs/routers/org"
  41. "github.com/gogits/gogs/routers/repo"
  42. "github.com/gogits/gogs/routers/user"
  43. )
  44. var CmdWeb = cli.Command{
  45. Name: "web",
  46. Usage: "Start Gogs web server",
  47. Description: `Gogs web server is the only thing you need to run,
  48. and it takes care of all the other things for you`,
  49. Action: runWeb,
  50. Flags: []cli.Flag{
  51. cli.StringFlag{"port, p", "3000", "Temporary port number to prevent conflict", ""},
  52. },
  53. }
  54. type VerChecker struct {
  55. ImportPath string
  56. Version func() string
  57. Expected string
  58. }
  59. // checkVersion checks if binary matches the version of templates files.
  60. func checkVersion() {
  61. // Templates.
  62. data, err := ioutil.ReadFile(path.Join(setting.StaticRootPath, "templates/.VERSION"))
  63. if err != nil {
  64. log.Fatal(4, "Fail to read 'templates/.VERSION': %v", err)
  65. }
  66. if string(data) != setting.AppVer {
  67. log.Fatal(4, "Binary and template file version does not match, did you forget to recompile?")
  68. }
  69. // Check dependency version.
  70. checkers := []VerChecker{
  71. {"github.com/Unknwon/macaron", macaron.Version, "0.5.1"},
  72. {"github.com/macaron-contrib/binding", binding.Version, "0.0.4"},
  73. {"github.com/macaron-contrib/cache", cache.Version, "0.0.7"},
  74. {"github.com/macaron-contrib/csrf", csrf.Version, "0.0.3"},
  75. {"github.com/macaron-contrib/i18n", i18n.Version, "0.0.5"},
  76. {"github.com/macaron-contrib/session", session.Version, "0.1.6"},
  77. {"gopkg.in/ini.v1", ini.Version, "1.2.0"},
  78. }
  79. for _, c := range checkers {
  80. ver := strings.Join(strings.Split(c.Version(), ".")[:3], ".")
  81. if git.MustParseVersion(ver).LessThan(git.MustParseVersion(c.Expected)) {
  82. log.Fatal(4, "Package '%s' version is too old(%s -> %s), did you forget to update?", c.ImportPath, ver, c.Expected)
  83. }
  84. }
  85. }
  86. // newMacaron initializes Macaron instance.
  87. func newMacaron() *macaron.Macaron {
  88. m := macaron.New()
  89. m.Use(macaron.Logger())
  90. m.Use(macaron.Recovery())
  91. if setting.EnableGzip {
  92. m.Use(macaron.Gziper())
  93. }
  94. if setting.Protocol == setting.FCGI {
  95. m.SetURLPrefix(setting.AppSubUrl)
  96. }
  97. m.Use(macaron.Static(
  98. path.Join(setting.StaticRootPath, "public"),
  99. macaron.StaticOptions{
  100. SkipLogging: !setting.DisableRouterLog,
  101. },
  102. ))
  103. m.Use(macaron.Static(
  104. setting.AvatarUploadPath,
  105. macaron.StaticOptions{
  106. Prefix: "avatars",
  107. SkipLogging: !setting.DisableRouterLog,
  108. },
  109. ))
  110. m.Use(macaron.Renderer(macaron.RenderOptions{
  111. Directory: path.Join(setting.StaticRootPath, "templates"),
  112. Funcs: []template.FuncMap{base.TemplateFuncs},
  113. IndentJSON: macaron.Env != macaron.PROD,
  114. }))
  115. m.Use(i18n.I18n(i18n.Options{
  116. SubURL: setting.AppSubUrl,
  117. Directory: path.Join(setting.ConfRootPath, "locale"),
  118. CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
  119. Langs: setting.Langs,
  120. Names: setting.Names,
  121. Redirect: true,
  122. }))
  123. m.Use(cache.Cacher(cache.Options{
  124. Adapter: setting.CacheAdapter,
  125. AdapterConfig: setting.CacheConn,
  126. Interval: setting.CacheInternal,
  127. }))
  128. m.Use(captcha.Captchaer(captcha.Options{
  129. SubURL: setting.AppSubUrl,
  130. }))
  131. m.Use(session.Sessioner(setting.SessionConfig))
  132. m.Use(csrf.Csrfer(csrf.Options{
  133. Secret: setting.SecretKey,
  134. SetCookie: true,
  135. Header: "X-Csrf-Token",
  136. CookiePath: setting.AppSubUrl,
  137. }))
  138. m.Use(toolbox.Toolboxer(m, toolbox.Options{
  139. HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
  140. &toolbox.HealthCheckFuncDesc{
  141. Desc: "Database connection",
  142. Func: models.Ping,
  143. },
  144. },
  145. }))
  146. // OAuth 2.
  147. if setting.OauthService != nil {
  148. for _, info := range setting.OauthService.OauthInfos {
  149. m.Use(oauth2.NewOAuth2Provider(info.Options, info.AuthUrl, info.TokenUrl))
  150. }
  151. }
  152. m.Use(middleware.Contexter())
  153. return m
  154. }
  155. func runWeb(ctx *cli.Context) {
  156. routers.GlobalInit()
  157. checkVersion()
  158. m := newMacaron()
  159. reqSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true})
  160. ignSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: setting.Service.RequireSignInView})
  161. ignSignInAndCsrf := middleware.Toggle(&middleware.ToggleOptions{DisableCsrf: true})
  162. reqSignOut := middleware.Toggle(&middleware.ToggleOptions{SignOutRequire: true})
  163. bind := binding.Bind
  164. bindIgnErr := binding.BindIgnErr
  165. // Routers.
  166. m.Get("/", ignSignIn, routers.Home)
  167. m.Get("/explore", ignSignIn, routers.Explore)
  168. m.Combo("/install", routers.InstallInit).
  169. Get(routers.Install).
  170. Post(bindIgnErr(auth.InstallForm{}), routers.InstallPost)
  171. m.Group("", func() {
  172. m.Get("/pulls", user.Pulls)
  173. m.Get("/issues", user.Issues)
  174. }, reqSignIn)
  175. // API.
  176. // FIXME: custom form error response.
  177. m.Group("/api", func() {
  178. m.Group("/v1", func() {
  179. // Miscellaneous.
  180. m.Post("/markdown", bindIgnErr(apiv1.MarkdownForm{}), v1.Markdown)
  181. m.Post("/markdown/raw", v1.MarkdownRaw)
  182. // Users.
  183. m.Group("/users", func() {
  184. m.Get("/search", v1.SearchUsers)
  185. m.Group("/:username", func() {
  186. m.Get("", v1.GetUserInfo)
  187. m.Group("/tokens", func() {
  188. m.Combo("").Get(v1.ListAccessTokens).Post(bind(v1.CreateAccessTokenForm{}), v1.CreateAccessToken)
  189. }, middleware.ApiReqBasicAuth())
  190. })
  191. })
  192. // Repositories.
  193. m.Combo("/user/repos", middleware.ApiReqToken()).Get(v1.ListMyRepos).Post(bind(api.CreateRepoOption{}), v1.CreateRepo)
  194. m.Post("/org/:org/repos", middleware.ApiReqToken(), bind(api.CreateRepoOption{}), v1.CreateOrgRepo)
  195. m.Group("/repos", func() {
  196. m.Get("/search", v1.SearchRepos)
  197. m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo)
  198. m.Group("/:username/:reponame", func() {
  199. m.Combo("/hooks").Get(v1.ListRepoHooks).Post(bind(api.CreateHookOption{}), v1.CreateRepoHook)
  200. m.Patch("/hooks/:id:int", bind(api.EditHookOption{}), v1.EditRepoHook)
  201. m.Get("/raw/*", middleware.RepoRef(), v1.GetRepoRawFile)
  202. }, middleware.ApiRepoAssignment(), middleware.ApiReqToken())
  203. })
  204. m.Any("/*", func(ctx *middleware.Context) {
  205. ctx.JSON(404, &base.ApiJsonErr{"Not Found", base.DOC_URL})
  206. })
  207. })
  208. })
  209. // User.
  210. m.Group("/user", func() {
  211. m.Get("/login", user.SignIn)
  212. m.Post("/login", bindIgnErr(auth.SignInForm{}), user.SignInPost)
  213. m.Get("/info/:name", user.SocialSignIn)
  214. m.Get("/sign_up", user.SignUp)
  215. m.Post("/sign_up", bindIgnErr(auth.RegisterForm{}), user.SignUpPost)
  216. m.Get("/reset_password", user.ResetPasswd)
  217. m.Post("/reset_password", user.ResetPasswdPost)
  218. }, reqSignOut)
  219. m.Group("/user/settings", func() {
  220. m.Get("", user.Settings)
  221. m.Post("", bindIgnErr(auth.UpdateProfileForm{}), user.SettingsPost)
  222. m.Post("/avatar", binding.MultipartForm(auth.UploadAvatarForm{}), user.SettingsAvatar)
  223. m.Get("/email", user.SettingsEmails)
  224. m.Post("/email", bindIgnErr(auth.AddEmailForm{}), user.SettingsEmailPost)
  225. m.Get("/password", user.SettingsPassword)
  226. m.Post("/password", bindIgnErr(auth.ChangePasswordForm{}), user.SettingsPasswordPost)
  227. m.Get("/ssh", user.SettingsSSHKeys)
  228. m.Post("/ssh", bindIgnErr(auth.AddSSHKeyForm{}), user.SettingsSSHKeysPost)
  229. m.Get("/social", user.SettingsSocial)
  230. m.Combo("/applications").Get(user.SettingsApplications).Post(bindIgnErr(auth.NewAccessTokenForm{}), user.SettingsApplicationsPost)
  231. m.Route("/delete", "GET,POST", user.SettingsDelete)
  232. }, reqSignIn)
  233. m.Group("/user", func() {
  234. // r.Get("/feeds", binding.Bind(auth.FeedsForm{}), user.Feeds)
  235. m.Any("/activate", user.Activate)
  236. m.Any("/activate_email", user.ActivateEmail)
  237. m.Get("/email2user", user.Email2User)
  238. m.Get("/forget_password", user.ForgotPasswd)
  239. m.Post("/forget_password", user.ForgotPasswdPost)
  240. m.Get("/logout", user.SignOut)
  241. })
  242. // Gravatar service.
  243. avt := avatar.CacheServer("public/img/avatar/", "public/img/avatar_default.jpg")
  244. os.MkdirAll("public/img/avatar/", os.ModePerm)
  245. m.Get("/avatar/:hash", avt.ServeHTTP)
  246. adminReq := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true, AdminRequire: true})
  247. m.Group("/admin", func() {
  248. m.Get("", adminReq, admin.Dashboard)
  249. m.Get("/config", admin.Config)
  250. m.Get("/monitor", admin.Monitor)
  251. m.Group("/users", func() {
  252. m.Get("", admin.Users)
  253. m.Get("/new", admin.NewUser)
  254. m.Post("/new", bindIgnErr(auth.RegisterForm{}), admin.NewUserPost)
  255. m.Get("/:userid", admin.EditUser)
  256. m.Post("/:userid", bindIgnErr(auth.AdminEditUserForm{}), admin.EditUserPost)
  257. m.Post("/:userid/delete", admin.DeleteUser)
  258. })
  259. m.Group("/orgs", func() {
  260. m.Get("", admin.Organizations)
  261. })
  262. m.Group("/repos", func() {
  263. m.Get("", admin.Repositories)
  264. })
  265. m.Group("/auths", func() {
  266. m.Get("", admin.Authentications)
  267. m.Get("/new", admin.NewAuthSource)
  268. m.Post("/new", bindIgnErr(auth.AuthenticationForm{}), admin.NewAuthSourcePost)
  269. m.Get("/:authid", admin.EditAuthSource)
  270. m.Post("/:authid", bindIgnErr(auth.AuthenticationForm{}), admin.EditAuthSourcePost)
  271. m.Post("/:authid/delete", admin.DeleteAuthSource)
  272. })
  273. m.Group("/notices", func() {
  274. m.Get("", admin.Notices)
  275. m.Get("/:id:int/delete", admin.DeleteNotice)
  276. })
  277. }, adminReq)
  278. m.Get("/:username", ignSignIn, user.Profile)
  279. if macaron.Env == macaron.DEV {
  280. m.Get("/template/*", dev.TemplatePreview)
  281. }
  282. reqTrueOwner := middleware.RequireTrueOwner()
  283. // Organization.
  284. m.Group("/org", func() {
  285. m.Get("/create", org.Create)
  286. m.Post("/create", bindIgnErr(auth.CreateOrgForm{}), org.CreatePost)
  287. m.Group("/:org", func() {
  288. m.Get("/dashboard", user.Dashboard)
  289. m.Get("/members", org.Members)
  290. m.Get("/members/action/:action", org.MembersAction)
  291. m.Get("/teams", org.Teams)
  292. m.Get("/teams/:team", org.TeamMembers)
  293. m.Get("/teams/:team/repositories", org.TeamRepositories)
  294. m.Get("/teams/:team/action/:action", org.TeamsAction)
  295. m.Get("/teams/:team/action/repo/:action", org.TeamsRepoAction)
  296. }, middleware.OrgAssignment(true, true))
  297. m.Group("/:org", func() {
  298. m.Get("/teams/new", org.NewTeam)
  299. m.Post("/teams/new", bindIgnErr(auth.CreateTeamForm{}), org.NewTeamPost)
  300. m.Get("/teams/:team/edit", org.EditTeam)
  301. m.Post("/teams/:team/edit", bindIgnErr(auth.CreateTeamForm{}), org.EditTeamPost)
  302. m.Post("/teams/:team/delete", org.DeleteTeam)
  303. m.Group("/settings", func() {
  304. m.Get("", org.Settings)
  305. m.Post("", bindIgnErr(auth.UpdateOrgSettingForm{}), org.SettingsPost)
  306. m.Get("/hooks", org.SettingsHooks)
  307. m.Get("/hooks/new", repo.WebHooksNew)
  308. m.Post("/hooks/gogs/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
  309. m.Post("/hooks/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost)
  310. m.Get("/hooks/:id", repo.WebHooksEdit)
  311. m.Post("/hooks/gogs/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
  312. m.Post("/hooks/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost)
  313. m.Route("/delete", "GET,POST", org.SettingsDelete)
  314. })
  315. m.Route("/invitations/new", "GET,POST", org.Invitation)
  316. }, middleware.OrgAssignment(true, true, true))
  317. }, reqSignIn)
  318. m.Group("/org", func() {
  319. m.Get("/:org", org.Home)
  320. }, middleware.OrgAssignment(true))
  321. // Repository.
  322. m.Group("/repo", func() {
  323. m.Get("/create", repo.Create)
  324. m.Post("/create", bindIgnErr(auth.CreateRepoForm{}), repo.CreatePost)
  325. m.Get("/migrate", repo.Migrate)
  326. m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), repo.MigratePost)
  327. m.Get("/fork", repo.Fork)
  328. m.Post("/fork", bindIgnErr(auth.CreateRepoForm{}), repo.ForkPost)
  329. }, reqSignIn)
  330. m.Group("/:username/:reponame", func() {
  331. m.Get("/settings", repo.Settings)
  332. m.Post("/settings", bindIgnErr(auth.RepoSettingForm{}), repo.SettingsPost)
  333. m.Group("/settings", func() {
  334. m.Route("/collaboration", "GET,POST", repo.SettingsCollaboration)
  335. m.Get("/hooks", repo.Webhooks)
  336. m.Get("/hooks/new", repo.WebHooksNew)
  337. m.Post("/hooks/gogs/new", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksNewPost)
  338. m.Post("/hooks/slack/new", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksNewPost)
  339. m.Get("/hooks/:id", repo.WebHooksEdit)
  340. m.Post("/hooks/gogs/:id", bindIgnErr(auth.NewWebhookForm{}), repo.WebHooksEditPost)
  341. m.Post("/hooks/slack/:id", bindIgnErr(auth.NewSlackHookForm{}), repo.SlackHooksEditPost)
  342. m.Group("/hooks/git", func() {
  343. m.Get("", repo.GitHooks)
  344. m.Get("/:name", repo.GitHooksEdit)
  345. m.Post("/:name", repo.GitHooksEditPost)
  346. }, middleware.GitHookService())
  347. })
  348. }, reqSignIn, middleware.RepoAssignment(true), reqTrueOwner)
  349. m.Group("/:username/:reponame", func() {
  350. m.Get("/action/:action", repo.Action)
  351. m.Group("/issues", func() {
  352. m.Get("/new", repo.CreateIssue)
  353. m.Post("/new", bindIgnErr(auth.CreateIssueForm{}), repo.CreateIssuePost)
  354. m.Post("/:index", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue)
  355. m.Post("/:index/label", repo.UpdateIssueLabel)
  356. m.Post("/:index/milestone", repo.UpdateIssueMilestone)
  357. m.Post("/:index/assignee", repo.UpdateAssignee)
  358. m.Get("/:index/attachment/:id", repo.IssueGetAttachment)
  359. m.Post("/labels/new", bindIgnErr(auth.CreateLabelForm{}), repo.NewLabel)
  360. m.Post("/labels/edit", bindIgnErr(auth.CreateLabelForm{}), repo.UpdateLabel)
  361. m.Post("/labels/delete", repo.DeleteLabel)
  362. m.Get("/milestones/new", repo.NewMilestone)
  363. m.Post("/milestones/new", bindIgnErr(auth.CreateMilestoneForm{}), repo.NewMilestonePost)
  364. m.Get("/milestones/:index/edit", repo.UpdateMilestone)
  365. m.Post("/milestones/:index/edit", bindIgnErr(auth.CreateMilestoneForm{}), repo.UpdateMilestonePost)
  366. m.Get("/milestones/:index/:action", repo.UpdateMilestone)
  367. })
  368. m.Post("/comment/:action", repo.Comment)
  369. m.Group("/releases", func() {
  370. m.Get("/new", repo.NewRelease)
  371. m.Post("/new", bindIgnErr(auth.NewReleaseForm{}), repo.NewReleasePost)
  372. m.Get("/edit/:tagname", repo.EditRelease)
  373. m.Post("/edit/:tagname", bindIgnErr(auth.EditReleaseForm{}), repo.EditReleasePost)
  374. }, middleware.RepoRef())
  375. }, reqSignIn, middleware.RepoAssignment(true))
  376. m.Group("/:username/:reponame", func() {
  377. m.Get("/releases", middleware.RepoRef(), repo.Releases)
  378. m.Get("/issues", repo.Issues)
  379. m.Get("/issues/:index", repo.ViewIssue)
  380. m.Get("/issues/milestones", repo.Milestones)
  381. m.Get("/pulls", repo.Pulls)
  382. m.Get("/branches", repo.Branches)
  383. m.Get("/archive/*", repo.Download)
  384. m.Get("/issues2/", repo.Issues2)
  385. m.Get("/pulls2/", repo.PullRequest2)
  386. m.Get("/labels2/", repo.Labels2)
  387. m.Get("/milestone2/", repo.Milestones2)
  388. m.Group("", func() {
  389. m.Get("/src/*", repo.Home)
  390. m.Get("/raw/*", repo.SingleDownload)
  391. m.Get("/commits/*", repo.RefCommits)
  392. m.Get("/commit/*", repo.Diff)
  393. }, middleware.RepoRef())
  394. m.Get("/compare/:before([a-z0-9]+)...:after([a-z0-9]+)", repo.CompareDiff)
  395. }, ignSignIn, middleware.RepoAssignment(true))
  396. m.Group("/:username", func() {
  397. m.Get("/:reponame", ignSignIn, middleware.RepoAssignment(true, true), middleware.RepoRef(), repo.Home)
  398. m.Any("/:reponame/*", ignSignInAndCsrf, repo.Http)
  399. })
  400. // robots.txt
  401. m.Get("/robots.txt", func(ctx *middleware.Context) {
  402. if setting.HasRobotsTxt {
  403. ctx.ServeFile(path.Join(setting.CustomPath, "robots.txt"))
  404. } else {
  405. ctx.Error(404)
  406. }
  407. })
  408. // Not found handler.
  409. m.NotFound(routers.NotFound)
  410. // Flag for port number in case first time run conflict.
  411. if ctx.IsSet("port") {
  412. setting.AppUrl = strings.Replace(setting.AppUrl, setting.HttpPort, ctx.String("port"), 1)
  413. setting.HttpPort = ctx.String("port")
  414. }
  415. var err error
  416. listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort)
  417. log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubUrl)
  418. switch setting.Protocol {
  419. case setting.HTTP:
  420. err = http.ListenAndServe(listenAddr, m)
  421. case setting.HTTPS:
  422. server := &http.Server{Addr: listenAddr, TLSConfig: &tls.Config{MinVersion: tls.VersionTLS10}, Handler: m}
  423. err = server.ListenAndServeTLS(setting.CertFile, setting.KeyFile)
  424. case setting.FCGI:
  425. err = fcgi.Serve(nil, m)
  426. default:
  427. log.Fatal(4, "Invalid protocol: %s", setting.Protocol)
  428. }
  429. if err != nil {
  430. log.Fatal(4, "Fail to start server: %v", err)
  431. }
  432. }