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