Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Task fixing html binder #2016

Merged
merged 2 commits into from
Jul 16, 2020
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
6 changes: 2 additions & 4 deletions binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ var (
IgnoreUnknownKeys: true,
})

// BaseRequestBinder is an instance of the requeBinder, it comes with preconfigured
// BaseRequestBinder is an instance of the requestBinder, it comes with preconfigured
// content type binders for HTML, JSON, XML and Files, as well as custom types decoders
// for time.Time and nulls.Time
BaseRequestBinder = NewRequestBinder(
HTMLContentTypeBinder{
decoder: formDecoder,
},
NewHTMLContentTypeBinder(formDecoder),
JSONContentTypeBinder{},
XMLRequestTypeBinder{},
FileRequestTypeBinder{
Expand Down
13 changes: 7 additions & 6 deletions binding/html_content_type_binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package binding

import (
"net/http"
"time"

"github.com/gobuffalo/buffalo/binding/decoders"
"github.com/gobuffalo/nulls"
"github.com/monoculum/formam"
)

Expand All @@ -15,14 +17,12 @@ type HTMLContentTypeBinder struct {
// NewHTMLContentTypeBinder returns an instance of HTMLContentTypeBinder with
// custom type decoders registered for Time and nulls.Time
func NewHTMLContentTypeBinder(decoder *formam.Decoder) HTMLContentTypeBinder {
htmlBinder := HTMLContentTypeBinder{
decoder.RegisterCustomType(decoders.TimeDecoderFn(), []interface{}{time.Time{}}, nil)
decoder.RegisterCustomType(decoders.NullTimeDecoderFn(), []interface{}{nulls.Time{}}, nil)

return HTMLContentTypeBinder{
decoder: decoder,
}

decoder.RegisterCustomType(decoders.TimeDecoderFn(), []interface{}{}, []interface{}{})
decoder.RegisterCustomType(decoders.NullTimeDecoderFn(), []interface{}{}, []interface{}{})

return htmlBinder
}

// ContentTypes that will be used to identify HTML requests
Expand All @@ -46,6 +46,7 @@ func (ht HTMLContentTypeBinder) BinderFunc() Binder {
if err := ht.decoder.Decode(req.Form, i); err != nil {
return err
}

return nil
}
}