github.com/rotblauer/buffalo@v0.7.1-0.20170112214545-7aa55ef80dd3/examples/json-resource/actions/app.go (about) 1 package actions 2 3 import ( 4 "os" 5 6 "github.com/gobuffalo/buffalo" 7 "github.com/gobuffalo/buffalo/examples/json-resource/models" 8 "github.com/gobuffalo/buffalo/middleware" 9 "github.com/markbates/going/defaults" 10 ) 11 12 // ENV is used to help switch settings based on where the 13 // application is being run. Default is "development". 14 var ENV = defaults.String(os.Getenv("GO_ENV"), "development") 15 var app *buffalo.App 16 17 // App is where all routes and middleware for buffalo 18 // should be defined. This is the nerve center of your 19 // application. 20 func App() *buffalo.App { 21 if app == nil { 22 app = buffalo.Automatic(buffalo.Options{ 23 Env: ENV, 24 }) 25 app.Use(middleware.SetContentType("application/json")) 26 app.Use(middleware.PopTransaction(models.DB)) 27 28 g := app.Resource("/users", &UsersResource{}) 29 g.Use(findUserMW) 30 } 31 32 return app 33 }