func main() { log.Info("Peach %s", APP_VER) m := macaron.New() m.Use(macaron.Logger()) m.Use(macaron.Recovery()) m.Use(macaron.Statics(macaron.StaticOptions{ SkipLogging: setting.ProdMode, }, "custom/public", "public")) m.Use(i18n.I18n(i18n.Options{ Files: setting.Docs.Locales, })) tplDir := "templates" if setting.Page.UseCustomTpl { tplDir = "custom/templates" } m.Use(pongo2.Pongoer(pongo2.Options{ Directory: tplDir, })) m.Use(middleware.Contexter()) m.Get("/", routers.Home) m.Get("/docs", routers.Docs) m.Get("/docs/images/*", routers.DocsStatic) m.Get("/docs/*", routers.Docs) m.Post("/hook", routers.Hook) m.Get("/search", routers.Search) m.Get("/*", routers.Pages) m.NotFound(routers.NotFound) listenAddr := fmt.Sprintf("0.0.0.0:%d", setting.HTTPPort) log.Info("%s Listen on %s", setting.Site.Name, listenAddr) log.Fatal("Fail to start Peach: %v", http.ListenAndServe(listenAddr, m)) }
func newInstance() *macaron.Macaron { m := macaron.New() m.Use(macaron.Logger()) m.Use(macaron.Recovery()) m.Use(macaron.Static("static")) m.Use(pongo2.Pongoer(pongo2.Options{ Directory: "views", IndentJSON: macaron.Env != macaron.PROD, IndentXML: macaron.Env != macaron.PROD, })) m.Use(cache.Cacher()) m.Use(session.Sessioner()) //DoXXX 表示GET请求; //OnXXX 表示POST请求; //AnyXXX 表示GET、POST混合请求 m.Any("/", AnyValidate) m.Get("/dogs", DoDogs) m.Get("/pups", DoPups) m.Get("/about", DoAbout) m.Get("/comment", DoComment) m.Get("/signin", DoSignin) m.Get("/dogDetail", DoDogDetail) m.Get("/pupDetail", DoPupDetail) m.Post("/onComment", OnComment) m.Post("/onSignin", OnSignin) return m }
func newMacaron() *macaron.Macaron { m := macaron.New() m.Use(macaron.Logger()) m.Use(macaron.Recovery()) m.Use(macaron.Static("static")) m.Use(session.Sessioner(session.Options{ Provider: "mysql", ProviderConfig: beego.AppConfig.String("mysqlstring"), })) m.Use(middleware.Contexter()) m.Use(pongo2.Pongoer(pongo2.Options{ Directory: "views", })) return m }
// newMacaron initializes Macaron instance. func newMacaron() *macaron.Macaron { m := macaron.New() m.Use(macaron.Logger()) m.Use(macaron.Recovery()) m.Use(macaron.Static("public", macaron.StaticOptions{ SkipLogging: setting.ProdMode, }, )) m.Use(macaron.Static("raw", macaron.StaticOptions{ Prefix: "raw", SkipLogging: setting.ProdMode, })) m.Use(pongo2.Pongoer(pongo2.Options{ IndentJSON: !setting.ProdMode, })) m.Use(i18n.I18n()) m.Use(session.Sessioner()) m.Use(middleware.Contexter()) return m }
func main() { setting.AppVer = APP_VER log.Info("%s %s", setting.AppName, setting.AppVer) log.Info("Run Mode: %s", strings.Title(macaron.Env)) m := macaron.Classic() m.Use(macaron.Static(setting.ArchivePath, macaron.StaticOptions{ Prefix: "/archive", })) m.Use(pongo2.Pongoer()) m.Use(middleware.Contexter()) m.Get("/", func(ctx *middleware.Context) { ctx.Data["Targets"] = models.Targets ctx.HTML(200, "home") }) if setting.Webhook.Mode == "test" { m.Get("/hook", func(ctx *middleware.Context) { if err := models.Build(ctx.Query("ref")); err != nil { ctx.JSON(500, map[string]interface{}{ "error": err.Error(), }) return } ctx.Status(200) }) } else { m.Post("/hook", func(ctx *middleware.Context) { }) } listenAddr := "0.0.0.0:" + com.ToStr(setting.HTTPPort) log.Info("Listen on http://%s", listenAddr) fmt.Println(http.ListenAndServe(listenAddr, m)) }