Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func buildFormDecoder() *formam.Decoder {
IgnoreUnknownKeys: true,
})

decoder.RegisterCustomType(decoders.TimeDecoderFn(), []interface{}{time.Time{}}, nil)
decoder.RegisterCustomType(decoders.NullTimeDecoderFn(), []interface{}{nulls.Time{}}, nil)
decoder.RegisterCustomType(decoders.TimeDecoderFn(), []any{time.Time{}}, nil)
decoder.RegisterCustomType(decoders.NullTimeDecoderFn(), []any{nulls.Time{}}, nil)

return decoder
}
Expand All @@ -55,8 +55,8 @@ func RegisterTimeFormats(layouts ...string) {

// RegisterCustomDecoder allows to define custom decoders for certain types
// In the request.
func RegisterCustomDecoder(fn CustomTypeDecoder, types []interface{}, fields []interface{}) {
rawFunc := (func([]string) (interface{}, error))(fn)
func RegisterCustomDecoder(fn CustomTypeDecoder, types []any, fields []any) {
rawFunc := (func([]string) (any, error))(fn)
formDecoder.RegisterCustomType(rawFunc, types, fields)
}

Expand All @@ -71,6 +71,6 @@ func Register(contentType string, fn Binder) {
// is "application/json" it will use "json.NewDecoder". If the type
// is "application/xml" it will use "xml.NewDecoder". The default
// binder is "https://github.com/monoculum/formam".
func Exec(req *http.Request, value interface{}) error {
func Exec(req *http.Request, value any) error {
return BaseRequestBinder.Exec(req, value)
}
10 changes: 5 additions & 5 deletions binding/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type blogPost struct {
func Test_Register(t *testing.T) {
r := require.New(t)

Register("foo/bar", func(*http.Request, interface{}) error {
Register("foo/bar", func(*http.Request, any) error {
return nil
})

Expand Down Expand Up @@ -47,13 +47,13 @@ func Test_Register(t *testing.T) {
func Test_RegisterCustomDecoder(t *testing.T) {
r := require.New(t)

RegisterCustomDecoder(func(vals []string) (interface{}, error) {
RegisterCustomDecoder(func(vals []string) (any, error) {
return []string{"X"}, nil
}, []interface{}{[]string{}}, nil)
}, []any{[]string{}}, nil)

RegisterCustomDecoder(func(vals []string) (interface{}, error) {
RegisterCustomDecoder(func(vals []string) (any, error) {
return 0, nil
}, []interface{}{int(0)}, nil)
}, []any{int(0)}, nil)

post := blogPost{}
req, err := http.NewRequest("POST", "/", nil)
Expand Down
4 changes: 2 additions & 2 deletions binding/decoders/null_time.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package decoders
import "github.com/gobuffalo/buffalo/internal/nulls"

// NullTimeDecoderFn is a custom type decoder func for null.Time fields
func NullTimeDecoderFn() func([]string) (interface{}, error) {
return func(vals []string) (interface{}, error) {
func NullTimeDecoderFn() func([]string) (any, error) {
return func(vals []string) (any, error) {
var ti nulls.Time

// If vals is empty, return a nulls.Time with Valid = false (i.e. NULL).
Expand Down
4 changes: 2 additions & 2 deletions binding/decoders/time.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package decoders

// TimeDecoderFn is a custom type decoder func for Time fields
func TimeDecoderFn() func([]string) (interface{}, error) {
return func(vals []string) (interface{}, error) {
func TimeDecoderFn() func([]string) (any, error) {
return func(vals []string) (any, error) {
return parseTime(vals)
}
}
2 changes: 1 addition & 1 deletion binding/file_request_type_binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (ht FileRequestTypeBinder) ContentTypes() []string {

// BinderFunc that will take care of the HTML File binding
func (ht FileRequestTypeBinder) BinderFunc() Binder {
return func(req *http.Request, i interface{}) error {
return func(req *http.Request, i any) error {
err := req.ParseMultipartForm(MaxFileMemory)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion binding/html_content_type_binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func (ht HTMLContentTypeBinder) ContentTypes() []string {

// BinderFunc that will take care of the HTML binding
func (ht HTMLContentTypeBinder) BinderFunc() Binder {
return func(req *http.Request, i interface{}) error {
return func(req *http.Request, i any) error {
err := req.ParseForm()
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion binding/json_content_type_binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type JSONContentTypeBinder struct{}

// BinderFunc returns the Binder for this JSONRequestTypeBinder
func (js JSONContentTypeBinder) BinderFunc() Binder {
return func(req *http.Request, value interface{}) error {
return func(req *http.Request, value any) error {
return json.NewDecoder(req.Body).Decode(value)
}
}
Expand Down
2 changes: 1 addition & 1 deletion binding/request_binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (rb *RequestBinder) Register(contentType string, fn Binder) {

// Exec binds a request with a passed value, depending on the content type
// It will look for the correct RequestTypeBinder and use it.
func (rb *RequestBinder) Exec(req *http.Request, value interface{}) error {
func (rb *RequestBinder) Exec(req *http.Request, value any) error {
rb.lock.Lock()
defer rb.lock.Unlock()

Expand Down
4 changes: 2 additions & 2 deletions binding/request_binder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func Test_RequestBinder_Exec(t *testing.T) {
r := require.New(t)

var used bool
BaseRequestBinder.Register("paganotoni/test", func(*http.Request, interface{}) error {
BaseRequestBinder.Register("paganotoni/test", func(*http.Request, any) error {
used = true
return nil
})
Expand All @@ -40,7 +40,7 @@ func Test_RequestBinder_Exec_BlankContentType(t *testing.T) {
func Test_RequestBinder_Exec_Bindable(t *testing.T) {
r := require.New(t)

BaseRequestBinder.Register("paganotoni/orbison", func(req *http.Request, val interface{}) error {
BaseRequestBinder.Register("paganotoni/orbison", func(req *http.Request, val any) error {
switch v := val.(type) {
case orbison:
v.bound = false
Expand Down
4 changes: 2 additions & 2 deletions binding/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type ContenTypeBinder interface {

// Binder takes a request and binds it to an interface.
// If there is a problem it should return an error.
type Binder func(*http.Request, interface{}) error
type Binder func(*http.Request, any) error

// CustomTypeDecoder converts a custom type from the request into its exact type.
type CustomTypeDecoder func([]string) (interface{}, error)
type CustomTypeDecoder func([]string) (any, error)
2 changes: 1 addition & 1 deletion binding/xml_request_type_binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type XMLRequestTypeBinder struct{}

// BinderFunc returns the Binder for this RequestTypeBinder
func (xm XMLRequestTypeBinder) BinderFunc() Binder {
return func(req *http.Request, value interface{}) error {
return func(req *http.Request, value any) error {
return xml.NewDecoder(req.Body).Decode(value)
}
}
Expand Down
14 changes: 7 additions & 7 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ type Context interface {
Cookies() *Cookies
Params() ParamValues
Param(string) string
Set(string, interface{})
LogField(string, interface{})
LogFields(map[string]interface{})
Set(string, any)
LogField(string, any)
LogFields(map[string]any)
Logger() Logger
Bind(interface{}) error
Bind(any) error
Render(int, render.Renderer) error
Error(int, error) error
Redirect(int, string, ...interface{}) error
Data() map[string]interface{}
Redirect(int, string, ...any) error
Data() map[string]any
Flash() *Flash
File(string) (binding.File, error)
}
Expand Down Expand Up @@ -70,7 +70,7 @@ func (a *App) newContext(info RouteInfo, res http.ResponseWriter, req *http.Requ
ct := httpx.ContentType(req)

data := newRequestData()
data.d = map[string]interface{}{
data.d = map[string]any{
"app": a,
"env": a.Env,
"routes": a.Routes(),
Expand Down
30 changes: 15 additions & 15 deletions default_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (d *DefaultContext) Param(key string) string {

// Set a value onto the Context. Any value set onto the Context
// will be automatically available in templates.
func (d *DefaultContext) Set(key string, value interface{}) {
func (d *DefaultContext) Set(key string, value any) {
if d.data == nil {
d.data = newRequestData()
}
Expand All @@ -78,7 +78,7 @@ func (d *DefaultContext) Set(key string, value interface{}) {
}

// Value that has previously stored on the context.
func (d *DefaultContext) Value(key interface{}) interface{} {
func (d *DefaultContext) Value(key any) any {
if k, ok := key.(string); ok && d.data != nil {
d.data.moot.RLock()
defer d.data.moot.RUnlock()
Expand Down Expand Up @@ -175,14 +175,14 @@ func (d *DefaultContext) Render(status int, rr render.Renderer) error {
// is "application/json" it will use "json.NewDecoder". If the type
// is "application/xml" it will use "xml.NewDecoder". See the
// github.com/gobuffalo/buffalo/binding package for more details.
func (d *DefaultContext) Bind(value interface{}) error {
func (d *DefaultContext) Bind(value any) error {
return binding.Exec(d.Request(), value)
}

// LogField adds the key/value pair onto the Logger to be printed out
// as part of the request logging. This allows you to easily add things
// like metrics (think DB times) to your request.
func (d *DefaultContext) LogField(key string, value interface{}) {
func (d *DefaultContext) LogField(key string, value any) {
if d.logger == nil {
return
}
Expand All @@ -192,7 +192,7 @@ func (d *DefaultContext) LogField(key string, value interface{}) {
// LogFields adds the key/value pairs onto the Logger to be printed out
// as part of the request logging. This allows you to easily add things
// like metrics (think DB times) to your request.
func (d *DefaultContext) LogFields(values map[string]interface{}) {
func (d *DefaultContext) LogFields(values map[string]any) {
if d.logger == nil {
return
}
Expand All @@ -203,10 +203,10 @@ func (d *DefaultContext) Error(status int, err error) error {
return HTTPError{Status: status, Cause: err}
}

var mapType = reflect.ValueOf(map[string]interface{}{}).Type()
var mapType = reflect.ValueOf(map[string]any{}).Type()

// Redirect a request with the given status to the given URL.
func (d *DefaultContext) Redirect(status int, url string, args ...interface{}) error {
func (d *DefaultContext) Redirect(status int, url string, args ...any) error {
if d.Session() != nil {
d.Flash().persist(d.Session())
if err := d.Session().Save(); err != nil {
Expand All @@ -216,15 +216,15 @@ func (d *DefaultContext) Redirect(status int, url string, args ...interface{}) e

if strings.HasSuffix(url, "Path()") {
if len(args) > 1 {
return fmt.Errorf("you must pass only a map[string]interface{} to a route path: %T", args)
return fmt.Errorf("you must pass only a map[string]any to a route path: %T", args)
}
var m map[string]interface{}
var m map[string]any
if len(args) == 1 {
rv := reflect.Indirect(reflect.ValueOf(args[0]))
if !rv.Type().ConvertibleTo(mapType) {
return fmt.Errorf("you must pass only a map[string]interface{} to a route path: %T", args)
return fmt.Errorf("you must pass only a map[string]any to a route path: %T", args)
}
m = rv.Convert(mapType).Interface().(map[string]interface{})
m = rv.Convert(mapType).Interface().(map[string]any)
}
h, ok := d.Value(strings.TrimSuffix(url, "()")).(RouteHelperFunc)
if !ok {
Expand All @@ -246,15 +246,15 @@ func (d *DefaultContext) Redirect(status int, url string, args ...interface{}) e
}

// Data contains all the values set through Get/Set.
func (d *DefaultContext) Data() map[string]interface{} {
m := map[string]interface{}{}
func (d *DefaultContext) Data() map[string]any {
m := map[string]any{}

if d.data == nil {
return m
}
d.data.moot.RLock()
defer d.data.moot.RUnlock()
m = make(map[string]interface{}, len(d.data.d))
m = make(map[string]any, len(d.data.d))
for k, v := range d.data.d {
m[k] = v
}
Expand Down Expand Up @@ -290,7 +290,7 @@ func (d *DefaultContext) File(name string) (binding.File, error) {

// MarshalJSON implements json marshaling for the context
func (d *DefaultContext) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{}
m := map[string]any{}
data := d.Data()
for k, v := range data {
// don't try and marshal ourself
Expand Down
8 changes: 4 additions & 4 deletions default_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ func Test_DefaultContext_Redirect_Helper(t *testing.T) {

table := []struct {
E string
I map[string]interface{}
I map[string]any
S int
}{
{
E: "/foo/baz/",
I: map[string]interface{}{"bar": "baz"},
I: map[string]any{"bar": "baz"},
S: http.StatusPermanentRedirect,
},
{
Expand Down Expand Up @@ -319,14 +319,14 @@ func Test_DefaultContext_Data(t *testing.T) {
r := require.New(t)
c := basicContext()

r.EqualValues(map[string]interface{}{}, c.Data())
r.EqualValues(map[string]any{}, c.Data())
}

func Test_DefaultContext_Data_not_configured(t *testing.T) {
r := require.New(t)
c := DefaultContext{}

r.EqualValues(map[string]interface{}{}, c.Data())
r.EqualValues(map[string]any{}, c.Data())
}

func Test_DefaultContext_String(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func defaultErrorHandler(status int, origErr error, c Context) error {
delete(cd, "app")
delete(cd, "routes")

data := map[string]interface{}{
data := map[string]any{
"routes": routes,
"error": trace,
"status": status,
Expand All @@ -259,7 +259,7 @@ func defaultErrorHandler(status int, origErr error, c Context) error {
"posted_form": c.Request().Form,
"context": c,
"headers": inspectHeaders(c.Request().Header),
"inspect": func(v interface{}) string {
"inspect": func(v any) string {
return fmt.Sprintf("%+v", v)
},
}
Expand Down
2 changes: 1 addition & 1 deletion internal/nulls/nulls.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Time struct {
}

// Scan implements the sql.Scanner interface.
func (t *Time) Scan(value interface{}) error {
func (t *Time) Scan(value any) error {
if value == nil {
t.Time, t.Valid = time.Time{}, false
return nil
Expand Down
4 changes: 2 additions & 2 deletions mail/mail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func Test_NewFromData(t *testing.T) {
r := require.New(t)
m := NewFromData(map[string]interface{}{
m := NewFromData(map[string]any{
"foo": "bar",
})
r.Equal("bar", m.Data["foo"])
Expand All @@ -36,7 +36,7 @@ func Test_New(t *testing.T) {
r.Equal("bar", m.Data["foo"])
rp, ok := m.Data["rootPath"].(buffalo.RouteHelperFunc)
r.True(ok)
x, err := rp(map[string]interface{}{})
x, err := rp(map[string]any{})
r.NoError(err)
r.Equal(template.HTML("/"), x)
}
4 changes: 2 additions & 2 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func newMiddlewareStack(mws ...MiddlewareFunc) *MiddlewareStack {
}
}

func funcKey(funcs ...interface{}) string {
func funcKey(funcs ...any) string {
names := []string{}
for _, f := range funcs {
if n, ok := f.(RouteInfo); ok {
Expand Down Expand Up @@ -216,7 +216,7 @@ func ptrName(ptr uintptr) string {
return n
}

func setFuncKey(f interface{}, name string) {
func setFuncKey(f any, name string) {
rv := reflect.ValueOf(f)
if rv.Kind() == reflect.Ptr {
rv = rv.Elem()
Expand Down
2 changes: 1 addition & 1 deletion not_found_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func Test_App_Dev_NotFound_JSON(t *testing.T) {
res := w.JSON("/bad").Get()
r.Equal(http.StatusNotFound, res.Code)

jb := map[string]interface{}{}
jb := map[string]any{}
err := json.NewDecoder(res.Body).Decode(&jb)
r.NoError(err)
r.Equal(float64(http.StatusNotFound), jb["code"])
Expand Down
Loading
Loading