本文整理汇总了Golang中github.com/Unknwon/macaron.Recovery函数的典型用法代码示例。如果您正苦于以下问题:Golang Recovery函数的具体用法?Golang Recovery怎么用?Golang Recovery使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Recovery函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
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))
}
开发者ID:0-T-0,项目名称:peach,代码行数:35,代码来源:peach.go
示例2: _StartMartini
func _StartMartini() {
WEB.Use(macaron.Recovery())
WEB.Use(macaron.Static("public",
macaron.StaticOptions{
FileSystem: bindata.Static(bindata.Options{
Asset: public.Asset,
AssetDir: public.AssetDir,
AssetNames: public.AssetNames,
Prefix: "",
}),
SkipLogging: true,
},
))
WEB.Use(macaron.Renderer(macaron.RenderOptions{
//Directory: "templates", //!!when package,escape this line. Specify what path to load the templates from.
Layout: "layout", // Specify a layout template. Layouts can call {{ yield }} to render the current template.
//Extensions: []string{".tmpl", ".html"}, //!!when package,escape this line. Specify extensions to load for templates.
//Charset: "UTF-8", //!!when package,escape this line. Sets encoding for json and html content-types. Default is "UTF-8".
TemplateFileSystem: bindata.Templates(bindata.Options{ //make templates files into bindata.
Asset: templates.Asset,
AssetDir: templates.AssetDir,
AssetNames: templates.AssetNames,
Prefix: ""}),
}))
LoadRoute()
WEB.Run(cfg.HOST, cfg.PORT)
}
开发者ID:luckykris,项目名称:shepherd,代码行数:28,代码来源:web.go
示例3: newMacaron
func newMacaron() *macaron.Macaron {
macaron.Env = setting.Env
m := macaron.New()
m.Use(middleware.Logger())
m.Use(macaron.Recovery())
if setting.EnableGzip {
m.Use(middleware.Gziper())
}
mapStatic(m, "", "public")
mapStatic(m, "app", "app")
mapStatic(m, "css", "css")
mapStatic(m, "img", "img")
mapStatic(m, "fonts", "fonts")
mapStatic(m, "robots.txt", "robots.txt")
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "views"),
IndentJSON: macaron.Env != macaron.PROD,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
if setting.EnforceDomain {
m.Use(middleware.ValidateHostHeader(setting.Domain))
}
m.Use(middleware.GetContextHandler())
m.Use(middleware.Sessioner(&setting.SessionOptions))
return m
}
开发者ID:toni-moreno,项目名称:grafana,代码行数:33,代码来源:web.go
示例4: newInstance
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
}
开发者ID:zileyuan,项目名称:hidog,代码行数:30,代码来源:main.go
示例5: SetMiddlewares
func SetMiddlewares(m *macaron.Macaron) {
m.Use(macaron.Static("static", macaron.StaticOptions{
Expires: func() string { return "max-age=0" },
}))
m.Map(Log)
m.Use(logger())
m.Use(macaron.Recovery())
}
开发者ID:pombredanne,项目名称:wharf-1,代码行数:10,代码来源:middleware.go
示例6: newMacaron
// newMacaron initializes Macaron instance.
func newMacaron() *macaron.Macaron {
m := macaron.New()
m.Use(macaron.Logger())
m.Use(macaron.Recovery())
if setting.EnableGzip {
m.Use(macaron.Gziper())
}
m.Use(macaron.Static(
path.Join(setting.StaticRootPath, "public"),
macaron.StaticOptions{
SkipLogging: !setting.DisableRouterLog,
},
))
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "templates"),
Funcs: []template.FuncMap{base.TemplateFuncs},
IndentJSON: macaron.Env != macaron.PROD,
}))
m.Use(i18n.I18n(i18n.Options{
SubURL: setting.AppSubUrl,
Directory: path.Join(setting.ConfRootPath, "locale"),
CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
Langs: setting.Langs,
Names: setting.Names,
Redirect: true,
}))
m.Use(cache.Cacher(cache.Options{
Adapter: setting.CacheAdapter,
Interval: setting.CacheInternal,
Conn: setting.CacheConn,
}))
m.Use(captcha.Captchaer(captcha.Options{
SubURL: setting.AppSubUrl,
}))
m.Use(session.Sessioner(session.Options{
Provider: setting.SessionProvider,
Config: *setting.SessionConfig,
}))
m.Use(csrf.Generate(csrf.Options{
Secret: setting.SecretKey,
SetCookie: true,
Header: "X-Csrf-Token",
CookiePath: setting.AppSubUrl,
}))
m.Use(toolbox.Toolboxer(m, toolbox.Options{
HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
&toolbox.HealthCheckFuncDesc{
Desc: "Database connection",
Func: models.Ping,
},
},
}))
m.Use(middleware.Contexter())
return m
}
开发者ID:ericcapricorn,项目名称:gogs,代码行数:56,代码来源:web.go
示例7: SetMiddlewares
func SetMiddlewares(m *macaron.Macaron) {
m.Use(macaron.Static("static", macaron.StaticOptions{
Expires: func() string { return "max-age=0" },
}))
InitLog(setting.RunMode, setting.LogPath)
m.Map(Log)
m.Use(logger(setting.RunMode))
m.Use(macaron.Recovery())
}
开发者ID:pombredanne,项目名称:wharf-1,代码行数:12,代码来源:middleware.go
示例8: newMacaron
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
}
开发者ID:trigrass2,项目名称:tech_oa,代码行数:16,代码来源:main.go
示例9: SetMiddlewares
func SetMiddlewares(m *macaron.Macaron) {
//Set static file directory,static file access without log output
m.Use(macaron.Static("external", macaron.StaticOptions{
Expires: func() string { return "max-age=0" },
}))
InitLog(setting.RunMode, setting.LogPath)
//Set global Logger
m.Map(Log)
//Set logger handler function, deal with all the Request log output
m.Use(logger(setting.RunMode))
//Set the response header info
m.Use(setRespHeaders())
//Set recovery handler to returns a middleware that recovers from any panics
m.Use(macaron.Recovery())
}
开发者ID:pombredanne,项目名称:wharf-1,代码行数:19,代码来源:middleware.go
示例10: SetMiddlewares
func SetMiddlewares(m *macaron.Macaron) {
m.Use(macaron.Static("external", macaron.StaticOptions{
Expires: func() string { return "max-age=0" },
}))
m.Map(Log)
//modify default template setting
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: "views",
Extensions: []string{".tmpl", ".html"},
Funcs: []template.FuncMap{},
Delims: macaron.Delims{"<<<", ">>>"},
Charset: "UTF-8",
IndentJSON: true,
IndentXML: true,
PrefixXML: []byte("macaron"),
HTMLContentType: "text/html",
}))
m.Use(macaron.Recovery())
}
开发者ID:liangchenye,项目名称:oct-web,代码行数:20,代码来源:middleware.go
示例11: newMacaron
func newMacaron() *macaron.Macaron {
macaron.Env = setting.Env
m := macaron.New()
m.Use(middleware.Logger())
m.Use(macaron.Recovery())
m.Use(toolbox.Toolboxer(m))
m.Use(func(ctx *macaron.Context) {
if ctx.Req.URL.Path == "/debug/vars" {
http.DefaultServeMux.ServeHTTP(ctx.Resp, ctx.Req.Request)
}
})
if setting.EnableGzip {
m.Use(middleware.Gziper())
}
mapStatic(m, "", "public")
mapStatic(m, "app", "app")
mapStatic(m, "css", "css")
mapStatic(m, "img", "img")
mapStatic(m, "fonts", "fonts")
mapStatic(m, "plugins", "plugins")
mapStatic(m, "robots.txt", "robots.txxt")
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "views"),
IndentJSON: macaron.Env != macaron.PROD,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
if setting.EnforceDomain {
m.Use(middleware.ValidateHostHeader(setting.Domain))
}
m.Use(middleware.GetContextHandler())
m.Use(middleware.Sessioner(&setting.SessionOptions))
return m
}
开发者ID:ronpastore,项目名称:grafana,代码行数:40,代码来源:web.go
示例12: newMacaron
// 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
}
开发者ID:fanbuchi,项目名称:gowalker,代码行数:23,代码来源:gowalker.go
示例13: newMacaron
func newMacaron() *macaron.Macaron {
macaron.Env = setting.Env
m := macaron.New()
m.Use(middleware.Logger())
m.Use(macaron.Recovery())
if setting.EnableGzip {
m.Use(middleware.Gziper())
}
for _, route := range plugins.StaticRoutes {
pluginRoute := path.Join("/public/plugins/", route.Url)
log.Info("Plugin: Adding static route %s -> %s", pluginRoute, route.Path)
mapStatic(m, route.Path, "", pluginRoute)
}
mapStatic(m, setting.StaticRootPath, "", "public")
mapStatic(m, setting.StaticRootPath, "app", "app")
mapStatic(m, setting.StaticRootPath, "css", "css")
mapStatic(m, setting.StaticRootPath, "img", "img")
mapStatic(m, setting.StaticRootPath, "fonts", "fonts")
mapStatic(m, setting.StaticRootPath, "robots.txt", "robots.txt")
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "views"),
IndentJSON: macaron.Env != macaron.PROD,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
if setting.EnforceDomain {
m.Use(middleware.ValidateHostHeader(setting.Domain))
}
m.Use(middleware.GetContextHandler())
m.Use(middleware.Sessioner(&setting.SessionOptions))
return m
}
开发者ID:mbrukman,项目名称:grafana,代码行数:39,代码来源:web.go
示例14: newMacaron
// newMacaron initializes Macaron instance.
func newMacaron() *macaron.Macaron {
m := macaron.New()
if !setting.DisableRouterLog {
m.Use(macaron.Logger())
}
m.Use(macaron.Recovery())
if setting.EnableGzip {
m.Use(macaron.Gziper())
}
if setting.Protocol == setting.FCGI {
m.SetURLPrefix(setting.AppSubUrl)
}
m.Use(macaron.Static(
path.Join(setting.StaticRootPath, "public"),
macaron.StaticOptions{
SkipLogging: setting.DisableRouterLog,
},
))
m.Use(macaron.Static(
setting.AvatarUploadPath,
macaron.StaticOptions{
Prefix: "avatars",
SkipLogging: setting.DisableRouterLog,
},
))
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: path.Join(setting.StaticRootPath, "templates"),
Funcs: []template.FuncMap{base.TemplateFuncs},
IndentJSON: macaron.Env != macaron.PROD,
}))
localeNames, err := bindata.AssetDir("conf/locale")
if err != nil {
log.Fatal(4, "Fail to list locale files: %v", err)
}
localFiles := make(map[string][]byte)
for _, name := range localeNames {
localFiles[name] = bindata.MustAsset("conf/locale/" + name)
}
m.Use(i18n.I18n(i18n.Options{
SubURL: setting.AppSubUrl,
Files: localFiles,
CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
Langs: setting.Langs,
Names: setting.Names,
Redirect: true,
}))
m.Use(cache.Cacher(cache.Options{
Adapter: setting.CacheAdapter,
AdapterConfig: setting.CacheConn,
Interval: setting.CacheInternal,
}))
m.Use(captcha.Captchaer(captcha.Options{
SubURL: setting.AppSubUrl,
}))
m.Use(session.Sessioner(setting.SessionConfig))
m.Use(csrf.Csrfer(csrf.Options{
Secret: setting.SecretKey,
SetCookie: true,
Header: "X-Csrf-Token",
CookiePath: setting.AppSubUrl,
}))
m.Use(toolbox.Toolboxer(m, toolbox.Options{
HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
&toolbox.HealthCheckFuncDesc{
Desc: "Database connection",
Func: models.Ping,
},
},
}))
// OAuth 2.
if setting.OauthService != nil {
for _, info := range setting.OauthService.OauthInfos {
m.Use(oauth2.NewOAuth2Provider(info.Options, info.AuthUrl, info.TokenUrl))
}
}
m.Use(middleware.Contexter())
return m
}
开发者ID:peterhadlaw,项目名称:gogs,代码行数:81,代码来源:web.go
示例15: main
func main() {
m := macaron.Classic()
// New permissions middleware
perm, err := permissionHSTORE.New()
if err != nil {
log.Fatalln(err)
}
// Blank slate, no default permissions
//perm.Clear()
// Logging middleware
m.Use(macaron.Logger())
// Renderer middleware
m.Use(macaron.Renderer())
// Set up a middleware handler for Macaron, with a custom "permission denied" message.
permissionHandler := func(ctx *macaron.Context) {
// Check if the user has the right admin/user rights
if perm.Rejected(ctx.Resp, ctx.Req.Request) {
fmt.Fprintf(ctx.Resp, "Permission denied!")
// Deny the request
ctx.Error(http.StatusForbidden)
// Don't call other middleware handlers
return
}
// Call the next middleware handler
ctx.Next()
}
// Enable the permissions middleware, must come before recovery
m.Use(permissionHandler)
// Recovery middleware
m.Use(macaron.Recovery())
// Get the userstate, used in the handlers below
userstate := perm.UserState()
m.Get("/", func(ctx *macaron.Context) (msg string) {
msg += fmt.Sprintf("Has user bob: %v\n", userstate.HasUser("bob"))
msg += fmt.Sprintf("Logged in on server: %v\n", userstate.IsLoggedIn("bob"))
msg += fmt.Sprintf("Is confirmed: %v\n", userstate.IsConfirmed("bob"))
msg += fmt.Sprintf("Username stored in cookies (or blank): %v\n", userstate.Username(ctx.Req.Request))
msg += fmt.Sprintf("Current user is logged in, has a valid cookie and *user rights*: %v\n", userstate.UserRights(ctx.Req.Request))
msg += fmt.Sprintf("Current user is logged in, has a valid cookie and *admin rights*: %v\n", userstate.AdminRights(ctx.Req.Request))
msg += fmt.Sprintln("\nTry: /register, /confirm, /remove, /login, /logout, /makeadmin, /clear, /data and /admin")
return // msg
})
m.Get("/register", func(ctx *macaron.Context) string {
userstate.AddUser("bob", "hunter1", "[email protected]")
return fmt.Sprintf("User bob was created: %v\n", userstate.HasUser("bob"))
})
m.Get("/confirm", func(ctx *macaron.Context) string {
userstate.MarkConfirmed("bob")
return fmt.Sprintf("User bob was confirmed: %v\n", userstate.IsConfirmed("bob"))
})
m.Get("/remove", func(ctx *macaron.Context) string {
userstate.RemoveUser("bob")
return fmt.Sprintf("User bob was removed: %v\n", !userstate.HasUser("bob"))
})
m.Get("/login", func(ctx *macaron.Context) string {
// Headers will be written, for storing a cookie
userstate.Login(ctx.Resp, "bob")
return fmt.Sprintf("bob is now logged in: %v\n", userstate.IsLoggedIn("bob"))
})
m.Get("/logout", func(ctx *macaron.Context) string {
userstate.Logout("bob")
return fmt.Sprintf("bob is now logged out: %v\n", !userstate.IsLoggedIn("bob"))
})
m.Get("/makeadmin", func(ctx *macaron.Context) string {
userstate.SetAdminStatus("bob")
return fmt.Sprintf("bob is now administrator: %v\n", userstate.IsAdmin("bob"))
})
m.Get("/clear", func(ctx *macaron.Context) string {
userstate.ClearCookie(ctx.Resp)
return "Clearing cookie"
})
m.Get("/data", func(ctx *macaron.Context) string {
return "user page that only logged in users must see!"
})
m.Get("/admin", func(ctx *macaron.Context) {
fmt.Fprintf(ctx.Resp, "super secret information that only logged in administrators must see!\n\n")
if usernames, err := userstate.AllUsernames(); err == nil {
fmt.Fprintf(ctx.Resp, "list of all users: "+strings.Join(usernames, ", "))
}
})
// Serve
//.........这里部分代码省略.........
开发者ID:xyproto,项目名称:permissiongres,代码行数:101,代码来源:main.go
示例16: main
func main() {
// initiate the app
m := macaron.Classic()
// register middleware
m.Use(macaron.Recovery())
m.Use(macaron.Gziper())
m.Use(macaron.Static("public",
macaron.StaticOptions{
// Prefix is the optional prefix used to serve the static directory content. Default is empty string.
Prefix: "public",
// SkipLogging will disable [Static] log messages when a static file is served. Default is false.
SkipLogging: true,
// IndexFile defines which file to serve as index if it exists. Default is "index.html".
IndexFile: "index.html",
// Expires defines which user-defined function to use for producing a HTTP Expires Header. Default is nil.
// https://developers.google.com/speed/docs/insights/LeverageBrowserCaching
Expires: func() string { return "max-age=0" },
}))
m.Use(session.Sessioner(session.Options{
// Name of provider. Default is "memory".
Provider: "memory",
// Provider configuration, it's corresponding to provider.
ProviderConfig: "",
// Cookie name to save session ID. Default is "MacaronSession".
CookieName: "MacaronSession",
// Cookie path to store. Default is "/".
CookiePath: "/",
// GC interval time in seconds. Default is 3600.
Gclifetime: 3600,
// Max life time in seconds. Default is whatever GC interval time is.
Maxlifetime: 3600,
// Use HTTPS only. Default is false.
Secure: false,
// Cookie life time. Default is 0.
CookieLifeTime: 0,
// Cookie domain name. Default is empty.
Domain: "",
// Session ID length. Default is 16.
IDLength: 16,
// Configuration section name. Default is "session".
Section: "session",
}))
m.Use(macaron.Renderer(macaron.RenderOptions{
// Directory to load templates. Default is "templates".
Directory: "templates",
// Extensions to parse template files from. Defaults are [".tmpl", ".html"].
Extensions: []string{".tmpl", ".html"},
// Funcs is a slice of FuncMaps to apply to the template upon compilation. Default is [].
Funcs: []template.FuncMap{map[string]interface{}{
"AppName": func() string {
return "Macaron"
},
"AppVer": func() string {
return "1.0.0"
},
}},
// Delims sets the action delimiters to the specified strings. Defaults are ["{{", "}}"].
Delims: macaron.Delims{"{{", "}}"},
// Appends the given charset to the Content-Type header. Default is "UTF-8".
Charset: "UTF-8",
// Outputs human readable JSON. Default is false.
IndentJSON: true,
// Outputs human readable XML. Default is false.
IndentXML: true,
// Prefixes the JSON output with the given bytes. Default is no prefix.
// PrefixJSON: []byte("macaron"),
// Prefixes the XML output with the given bytes. Default is no prefix.
// PrefixXML: []byte("macaron"),
// Allows changing of output to XHTML instead of HTML. Default is "text/html".
HTMLContentType: "text/html",
}))
m.Use(cache.Cacher(cache.Options{
// Name of adapter. Default is "memory".
Adapter: "memory",
// Adapter configuration, it's corresponding to adapter.
AdapterConfig: "",
// GC interval time in seconds. Default is 60.
Interval: 60,
// Configuration section name. Default is "cache".
Section: "cache",
}))
// setup handlers
m.Get("/", myHandler)
m.Get("/welcome", myOtherHandler)
m.Get("/query", myQueryStringHandler) // /query?name=Some+Name
m.Get("/json", myJsonHandler)
m.Post("/contact/submit", binding.Bind(ContactForm{}), mySubmitHandler)
m.Get("/session", mySessionHandler)
m.Get("/set/cookie/:value", mySetCookieHandler)
m.Get("/get/cookie", myGetCookieHandler)
m.Get("/database", myDatabaseHandler)
m.Get("/database/list", myDatabaseListHandler)
m.Get("/cache/write/:key/:value", myCacheWriteHandler)
m.Get("/cache/read/:key", myCacheReadHandler)
log.Println("Server is running on localhost:4000...")
log.Println(http.ListenAndServe("0.0.0.0:4000", m))
}
开发者ID:james2doyle,项目名称:macaron-example,代码行数:100,代码来源:main.go
示例17: daemon
func daemon(c *cobra.Command, a []string) {
m := macaron.New()
setting.NewContext(c)
err := models.NewEngine()
m.Use(middleware.Contexter())
m.Use(macaron.Recovery())
m.Use(macaron.Logger())
m.Use(macaron.Renderer(
macaron.RenderOptions{
Directory: "templates",
TemplateFileSystem: bindata.Templates(bindata.Options{
Asset: templates.Asset,
AssetDir: templates.AssetDir,
AssetNames: templates.AssetNames,
Prefix: "",
}),
},
))
m.Use(macaron.Static("web/images",
macaron.StaticOptions{
Prefix: "images",
FileSystem: bindata.Static(bindata.Options{
Asset: web.Asset,
AssetDir: web.AssetDir,
AssetNames: web.AssetNames,
Prefix: "web/images",
}),
},
))
m.Use(macaron.Static("web/template",
macaron.StaticOptions{
Prefix: "template",
FileSystem: bindata.Static(bindata.Options{
Asset: web.Asset,
AssetDir: web.AssetDir,
AssetNames: web.AssetNames,
Prefix: "web/template",
}),
},
))
m.Use(macaron.Static("web",
macaron.StaticOptions{
FileSystem: bindata.Static(bindata.Options{
Asset: web.Asset,
AssetDir: web.AssetDir,
AssetNames: web.AssetNames,
Prefix: "web",
}),
Prefix: viper.GetString("version"),
},
))
m.Get("/assets/html/user/views/oauth.html", user.OauthHandler)
m.Combo("/api/oauth").
Get(user.OauthUrl).
Post(binding.Json(auth.Oauth2{}), user.OauthLogin)
m.Post("/api/login", binding.Json(auth.SignIn{}), user.SignIn)
m.Post("/api/register", binding.Json(auth.SignUp{}), user.SignUp)
m.Group("/api", func() {
m.Get("/boards", board.ListBoards)
m.Post("/boards/configure", binding.Json(models.BoardRequest{}), board.Configure)
m.Get("/board", board.ItemBoard)
m.Get("/labels", board.ListLabels)
m.Get("/cards", board.ListCards)
m.Get("/milestones", board.ListMilestones)
m.Get("/users", board.ListMembers)
m.Combo("/comments").
Get(board.ListComments).
Post(binding.Json(models.CommentRequest{}), board.CreateComment)
m.Combo("/card").
Post(binding.Json(models.CardRequest{}), board.CreateCard).
Put(binding.Json(models.CardRequest{}), board.UpdateCard).
Delete(binding.Json(models.CardRequest{}), board.DeleteCard)
m.Put("/card/move", binding.Json(models.CardRequest{}), board.MoveToCard)
}, middleware.Auther())
m.Get("/*", routers.Home)
m.Get("/ws/", sockets.Messages(), ws.ListenAndServe)
listen := viper.GetString("server.listen")
log.Printf("Listen: %s", listen)
err = http.ListenAndServe(listen, m)
if err != nil {
log.Fatalf("Failed to start: %s", err)
}
}
开发者ID:praveenscience,项目名称:kanban,代码行数:93,代码来源:daemon.go
示例18: main
func main() {
log.Info("%s %s", setting.AppName, APP_VER)
log.Info("Run Mode: %s", strings.Title(macaron.Env))
m := macaron.New()
m.Use(macaron.Logger())
m.Use(macaron.Recovery())
m.Use(macaron.Static("public", macaron.StaticOptions{
SkipLogging: true,
}))
m.Use(pongo2.Pongoers(pongo2.Options{
Directory: "templates/web",
IndentJSON: macaron.Env != macaron.PROD,
}, "templates/admin"))
m.Use(i18n.I18n())
m.Use(session.Sessioner())
m.Use(middleware.Contexter())
// Routes.
m.Get("/", routers.Home)
m.Route("/download", "GET,POST", routers.Download)
m.Get("/favicon.ico", func(ctx *middleware.Context) {
ctx.Redirect("/img/favicon.png")
})
// m.Get("/search", routers.Search)
// m.Get("/about", routers.About)
// Package.
m.Get("/*", routers.Package)
m.Get("/badge/*", routers.Badge)
// Admin.
m.Post("/admin/auth", admin.AuthPost)
m.Group("/admin", func() {
m.Get("", admin.Dashboard)
m.Group("/packages", func() {
m.Get("", admin.Revisions)
m.Get("/larges", admin.LargeRevisions)
})
m.Group("/blocks", func() {
m.Get("", admin.Blocks)
m.Combo("/new").Get(admin.BlockPackage).Post(admin.BlockPackagePost)
m.Get("/:id:int/delete", admin.UnblockPackage)
m.Group("/rules", func() {
m.Get("", admin.BlockRules)
m.Combo("/new").Get(admin.NewBlockRule).Post(admin.NewBlockRulePost)
m.Get("/:id:int/run", admin.RunRule)
m.Get("/:id:int/delete", admin.DeleteBlockRule)
})
})
}, admin.Auth)
// API.
m.Group("/api", func() {
m.Group("/v1", func() {
m.Group("", func() {
m.Get("/download", v1.Download)
m.Get("/revision", v1.GetRevision)
}, v1.PackageFilter())
})
})
// Robots.txt
m.Get("/robots.txt", func() string {
return `User-agent: *
Disallow: /api/
Disallow: /download`
})
m.NotFound(routers.NotFound)
listenAddr := fmt.Sprintf("0.0.0.0:%d", setting.HttpPort)
log.Info("Listen: http://%s", listenAddr)
if err := http.ListenAndServe(listenAddr, m); err != nil {
log.Fatal(4, "Fail to start server: %v", err)
}
}
开发者ID:harryyeh,项目名称:switch,代码行数:80,代码来源:switch.go
示例19: runWeb
func runWeb(c *cli.Context) {
if err := models.InitDb(); err != nil {
log.Fatal("Fail to init DB: %v", err)
}
if c.IsSet("port") {
setting.HTTPPort = c.Int("port")
}
bindIgnErr := binding.BindIgnErr
m := macaron.New()
m.Use(macaron.Logger())
m.Use(macaron.Recovery())
m.Use(macaron.Renderer(macaron.RenderOptions{
IndentJSON: !setting.ProdMode,
}))
m.Use(web.Contexter())
group := func() {
m.Group("/flows", func() {
m.Combo("").Get(web.Flows).
Post(bindIgnErr(api.CreateFlowOptions{}), web.CreateFlow)
m.Combo("/:uuid").Get(web.GetFlow).
Post(bindIgnErr(api.CreateFlowOptions{}), web.UpdateFlow).
Delete(web.DeleteFlow)
})
m.Group("/pipelines", func() {
m.Combo("").Get(web.Pipelines).
Post(bindIgnErr(api.CreatePipelineOptions{}), web.CreatePipeline)
m.Combo("/:uuid").Get(web.GetPipeline).
Post(bindIgnErr(api.CreatePipelineOptions{}), web.UpdatePipeline).
Delete(web.DeletePipeline)
})
m.Group("/stages", func() {
m.Combo("").Get(web.Stages).
Post(bindIgnErr(api.CreateStageOptions{}), web.CreateStage)
m.Combo("/:uuid").Get(web.GetStage).
Post(bindIgnErr(api.CreateStageOptions{}), web.UpdateStage).
Delete(web.DeleteStage)
})
m.Group("/jobs", func() {
m.Combo("").Get(web.Jobs).
Post(bindIgnErr(api.CreateJobOptions{}), web.CreateJob)
m.Combo("/:uuid").Get(web.GetJob).
Post(bindIgnErr(api.CreateJobOptions{}), web.UpdateJob).
Delete(web.DeleteJob)
})
m.Post("/build", web.Build)
}
m.Group("", group)
m.Group("/v1", group)
listenAddr := fmt.Sprintf("0.0.0.0:%d", setting.HTTPPort)
log.Info("Vessel %s %s", setting.AppVer, listenAddr)
if err := http.ListenAndServe(listenAddr, m); err != nil {
log.Fatal("Fail to start web server: %v", err)
}
}
开发者ID:rechen,项目名称:vessel,代码行数:63,代码来源:web.go
注:本文中的github.com/Unknwon/macaron.Recovery函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论