Skip to content

Commit d7a616b

Browse files
committed
deprecated "Automatic" in favor of just "New".
1 parent b6bc050 commit d7a616b

13 files changed

+43
-45
lines changed

app.go

+15-17
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package buffalo
33
import (
44
"context"
55
"fmt"
6+
"log"
67
"net/http"
78
"os"
9+
"runtime"
810
"strings"
911
"sync"
1012
"syscall"
@@ -118,9 +120,7 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
118120
h.ServeHTTP(ws, r)
119121
}
120122

121-
// New returns a new instance of App, without any frills
122-
// or thrills. Most people will want to use Automatic which
123-
// adds some sane, and useful, defaults.
123+
// New returns a new instance of App and adds some sane, and useful, defaults.
124124
func New(opts Options) *App {
125125
opts = optionsWithDefaults(opts)
126126

@@ -142,28 +142,26 @@ func New(opts Options) *App {
142142
a.ErrorHandlers.Get(404)(404, err, c)
143143
})
144144

145-
return a
146-
}
147-
148-
// Automatic returns a new instance of App with sane defaults,
149-
// some not so sane defaults, and a few bits and pieces to make
150-
// your life that much easier. You'll want to use this almost
151-
// all of the time to build your applications.
152-
//
153-
// https://www.youtube.com/watch?v=BKbOplYmjZM
154-
func Automatic(opts Options) *App {
155-
opts = optionsWithDefaults(opts)
156-
157-
a := New(opts)
158-
159145
if a.MethodOverride == nil {
160146
a.MethodOverride = MethodOverride
161147
}
162148
a.Use(a.PanicHandler)
163149
a.Use(RequestLogger)
150+
164151
return a
165152
}
166153

154+
func Automatic(opts Options) *App {
155+
warningMsg := "Automatic is deprecated, and will be removed in v0.10.0. Use buffalo.New instead."
156+
_, file, no, ok := runtime.Caller(1)
157+
if ok {
158+
warningMsg = fmt.Sprintf("%s Called from %s:%d", warningMsg, file, no)
159+
}
160+
161+
log.Println(warningMsg)
162+
return New(opts)
163+
}
164+
167165
func (a *App) processPreHandlers(res http.ResponseWriter, req *http.Request) bool {
168166
sh := func(h http.Handler) bool {
169167
h.ServeHTTP(res, req)

default_context_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func basicContext() DefaultContext {
3030

3131
func Test_DefaultContext_Redirect(t *testing.T) {
3232
r := require.New(t)
33-
a := Automatic(Options{})
33+
a := New(Options{})
3434
u := "/foo?bar=http%3A%2F%2Flocalhost%3A3000%2Flogin%2Fcallback%2Ffacebook"
3535
a.GET("/", func(c Context) error {
3636
return c.Redirect(302, u)
@@ -230,7 +230,7 @@ func Test_DefaultContext_Websocket(t *testing.T) {
230230
Received time.Time `json:"received"`
231231
}
232232

233-
a := Automatic(Options{})
233+
a := New(Options{})
234234
a.GET("/socket", func(c Context) error {
235235
conn, err := c.Websocket()
236236
if err != nil {

flash_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func Test_FlashAdd(t *testing.T) {
2727

2828
func Test_FlashRender(t *testing.T) {
2929
r := require.New(t)
30-
a := Automatic(Options{})
30+
a := New(Options{})
3131
rr := render.New(render.Options{})
3232

3333
a.GET("/", func(c Context) error {
@@ -46,7 +46,7 @@ func Test_FlashRender(t *testing.T) {
4646

4747
func Test_FlashRenderEmpty(t *testing.T) {
4848
r := require.New(t)
49-
a := Automatic(Options{})
49+
a := New(Options{})
5050
rr := render.New(render.Options{})
5151

5252
a.GET("/", func(c Context) error {
@@ -68,7 +68,7 @@ const errorsTPL = `
6868

6969
func Test_FlashRenderEntireFlash(t *testing.T) {
7070
r := require.New(t)
71-
a := Automatic(Options{})
71+
a := New(Options{})
7272
rr := render.New(render.Options{})
7373

7474
a.GET("/", func(c Context) error {
@@ -89,7 +89,7 @@ const keyTPL = `<%= for (k, v) in flash { %>
8989

9090
func Test_FlashRenderCustomKey(t *testing.T) {
9191
r := require.New(t)
92-
a := Automatic(Options{})
92+
a := New(Options{})
9393
rr := render.New(render.Options{})
9494

9595
a.GET("/", func(c Context) error {
@@ -104,7 +104,7 @@ func Test_FlashRenderCustomKey(t *testing.T) {
104104

105105
func Test_FlashRenderCustomKeyNotDefined(t *testing.T) {
106106
r := require.New(t)
107-
a := Automatic(Options{})
107+
a := New(Options{})
108108
rr := render.New(render.Options{})
109109

110110
a.GET("/", func(c Context) error {

generators/helpers_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var ENV = defaults.String(os.Getenv("GO_ENV"), "development")
3535
var app *buffalo.App
3636
func App() *buffalo.App {
3737
if app == nil {
38-
app = buffalo.Automatic(buffalo.Options{
38+
app = buffalo.New(buffalo.Options{
3939
Env: ENV,
4040
})
4141
@@ -74,7 +74,7 @@ var ENV = defaults.String(os.Getenv("GO_ENV"), "development")
7474
var app *buffalo.App
7575
func App() *buffalo.App {
7676
if app == nil {
77-
app = buffalo.Automatic(buffalo.Options{
77+
app = buffalo.New(buffalo.Options{
7878
Env: ENV,
7979
})
8080

generators/newapp/templates/actions/app.go.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var T *i18n.Translator
3535
// application.
3636
func App() *buffalo.App {
3737
if app == nil {
38-
app = buffalo.Automatic(buffalo.Options{
38+
app = buffalo.New(buffalo.Options{
3939
Env: ENV,
4040
{{ if .asAPI -}}
4141
SessionStore: sessions.Null{},

method_override.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
// Options#MethodOverride. By default it will look for a form value
1111
// name `_method` and change the request method if that is
1212
// present and the original request is of type "POST". This is
13-
// added automatically when using `Automatic` Buffalo, unless
13+
// added automatically when using `New` Buffalo, unless
1414
// an alternative is defined in the Options.
1515
func MethodOverride(res http.ResponseWriter, req *http.Request) {
1616
if req.Method == "POST" {

method_override_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
func Test_MethodOverride(t *testing.T) {
1313
r := require.New(t)
1414

15-
a := Automatic(Options{})
15+
a := New(Options{})
1616
a.PUT("/", func(c Context) error {
1717
return c.Render(200, render.String("you put me!"))
1818
})

middleware/basicauth/basicauth_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func app() *buffalo.App {
1818
auth := func(c buffalo.Context, u, p string) (bool, error) {
1919
return (u == "tester" && p == "pass123"), nil
2020
}
21-
a := buffalo.Automatic(buffalo.Options{})
21+
a := buffalo.New(buffalo.Options{})
2222
a.Use(basicauth.Middleware(auth))
2323
a.GET("/", h)
2424
return a

middleware/content_type_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func ctApp() *buffalo.App {
1414
h := func(c buffalo.Context) error {
1515
return c.Render(200, render.String(c.Request().Header.Get("Content-Type")))
1616
}
17-
a := buffalo.Automatic(buffalo.Options{})
17+
a := buffalo.New(buffalo.Options{})
1818
a.GET("/set", middleware.SetContentType("application/json")(h))
1919
a.GET("/add", middleware.AddContentType("application/json")(h))
2020
return a

middleware/csrf/csrf_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func ctCSRFApp() *buffalo.App {
2121
}
2222
return c.Render(420, nil)
2323
}
24-
a := buffalo.Automatic(buffalo.Options{})
24+
a := buffalo.New(buffalo.Options{})
2525
a.Use(middleware.CSRF)
2626
a.GET("/csrf", h)
2727
a.POST("/csrf", h)

middleware/i18n/i18n_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func app() *buffalo.App {
15-
app := buffalo.Automatic(buffalo.Options{})
15+
app := buffalo.New(buffalo.Options{})
1616

1717
r := render.New(render.Options{
1818
TemplatesBox: packr.NewBox("./templates"),

not_found_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func Test_App_Dev_NotFound(t *testing.T) {
1212
r := require.New(t)
1313

14-
a := Automatic(Options{})
14+
a := New(Options{})
1515
a.Env = "development"
1616
a.GET("/foo", func(c Context) error { return nil })
1717

@@ -27,7 +27,7 @@ func Test_App_Dev_NotFound(t *testing.T) {
2727
func Test_App_Dev_NotFound_JSON(t *testing.T) {
2828
r := require.New(t)
2929

30-
a := Automatic(Options{})
30+
a := New(Options{})
3131
a.Env = "development"
3232
a.GET("/foo", func(c Context) error { return nil })
3333

router_test.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,15 @@ func Test_Router_Group_Middleware(t *testing.T) {
258258

259259
a := testApp()
260260
a.Use(func(h Handler) Handler { return h })
261-
r.Len(a.Middleware.stack, 1)
261+
r.Len(a.Middleware.stack, 3)
262262

263263
g := a.Group("/api/v1")
264-
r.Len(a.Middleware.stack, 1)
265-
r.Len(g.Middleware.stack, 1)
264+
r.Len(a.Middleware.stack, 3)
265+
r.Len(g.Middleware.stack, 3)
266266

267267
g.Use(func(h Handler) Handler { return h })
268-
r.Len(a.Middleware.stack, 1)
269-
r.Len(g.Middleware.stack, 2)
268+
r.Len(a.Middleware.stack, 3)
269+
r.Len(g.Middleware.stack, 4)
270270
}
271271

272272
func Test_Router_Redirect(t *testing.T) {
@@ -304,7 +304,7 @@ func Test_App_NamedRoutes(t *testing.T) {
304304
}
305305

306306
r := require.New(t)
307-
a := Automatic(Options{})
307+
a := New(Options{})
308308

309309
var carsResource Resource
310310
carsResource = CarsResource{&BaseResource{}}
@@ -405,7 +405,7 @@ func Test_Resource(t *testing.T) {
405405
},
406406
}
407407

408-
a := Automatic(Options{})
408+
a := New(Options{})
409409
a.Resource("/users", &userResource{})
410410
a.Resource("/api/v1/users", &userResource{})
411411

@@ -474,14 +474,14 @@ func Test_buildRouteName(t *testing.T) {
474474
"/admin/planes/{plane_id}/edit": "editAdminPlane",
475475
}
476476

477-
a := Automatic(Options{})
477+
a := New(Options{})
478478

479479
for input, result := range cases {
480480
fResult := a.buildRouteName(input)
481481
r.Equal(result, fResult, input)
482482
}
483483

484-
a = Automatic(Options{Prefix: "/test"})
484+
a = New(Options{Prefix: "/test"})
485485
cases = map[string]string{
486486
"/test": "test",
487487
"/test/users": "testUsers",
@@ -497,7 +497,7 @@ func Test_CatchAll_Route(t *testing.T) {
497497
r := require.New(t)
498498
rr := render.New(render.Options{})
499499

500-
a := Automatic(Options{})
500+
a := New(Options{})
501501
a.GET("/{name:.+}", func(c Context) error {
502502
name := c.Param("name")
503503
return c.Render(200, rr.String(name))

0 commit comments

Comments
 (0)