github.com/jasonish/buffalo@v0.8.2-0.20170413145823-bacbdd415f1b/generators/newapp/templates/actions/app.go.tmpl (about) 1 package actions 2 3 import ( 4 "log" 5 "github.com/gobuffalo/buffalo" 6 "github.com/gobuffalo/buffalo/middleware" 7 "github.com/gobuffalo/buffalo/middleware/i18n" 8 {{ if .withPop }} 9 "{{.modelsPath}}" 10 {{ end }} 11 "github.com/gobuffalo/envy" 12 "github.com/gobuffalo/packr" 13 ) 14 15 // ENV is used to help switch settings based on where the 16 // application is being run. Default is "development". 17 var ENV = envy.Get("GO_ENV", "development") 18 var app *buffalo.App 19 var T *i18n.Translator 20 21 // App is where all routes and middleware for buffalo 22 // should be defined. This is the nerve center of your 23 // application. 24 func App() *buffalo.App { 25 if app == nil { 26 app = buffalo.Automatic(buffalo.Options{ 27 Env: ENV, 28 SessionName: "_{{.name}}_session", 29 }) 30 if ENV == "development" { 31 app.Use(middleware.ParameterLogger) 32 } 33 // Protect against CSRF attacks. https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF) 34 // Remove to disable this. 35 app.Use(middleware.CSRF) 36 37 {{ if .withPop }} 38 app.Use(middleware.PopTransaction(models.DB)) 39 {{ end }} 40 41 // Setup and use translations: 42 var err error 43 T, err = i18n.New(packr.NewBox("../locales"), "en-US") 44 if err != nil { 45 log.Fatal(err) 46 } 47 app.Use(T.Middleware()) 48 49 app.GET("/", HomeHandler) 50 51 app.ServeFiles("/assets", packr.NewBox("../public/assets")) 52 } 53 54 return app 55 }