github.com/jasonish/buffalo@v0.8.2-0.20170413145823-bacbdd415f1b/examples/html-resource/actions/app.go (about) 1 package actions 2 3 import ( 4 "net/http" 5 "os" 6 7 "github.com/gobuffalo/buffalo" 8 "github.com/gobuffalo/buffalo/examples/html-resource/models" 9 "github.com/gobuffalo/buffalo/middleware" 10 "github.com/gobuffalo/packr" 11 "github.com/markbates/going/defaults" 12 ) 13 14 // ENV is used to help switch settings based on where the 15 // application is being run. Default is "development". 16 var ENV = defaults.String(os.Getenv("GO_ENV"), "development") 17 var app *buffalo.App 18 19 // App is where all routes and middleware for buffalo 20 // should be defined. This is the nerve center of your 21 // application. 22 func App() *buffalo.App { 23 if app == nil { 24 app = buffalo.Automatic(buffalo.Options{ 25 Env: ENV, 26 }) 27 28 app.ServeFiles("/assets", packr.NewBox("../assets")) 29 app.Use(middleware.PopTransaction(models.DB)) 30 app.GET("/", func(c buffalo.Context) error { 31 return c.Redirect(http.StatusPermanentRedirect, "/users") 32 }) 33 34 g := app.Resource("/users", &UsersResource{}) 35 g.Use(findUserMW("user_id")) 36 37 g = app.Resource("/people", &UsersResource{}) 38 g.Use(findUserMW("person_id")) 39 } 40 41 return app 42 }