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

Commit

Permalink
v0.16.9 (#1996)
Browse files Browse the repository at this point in the history
* merge changes from buffalo-cli into main repo

* cache deps before building and copying source (#1884)

cache deps before building and copying source so that we don't need to re-download as much
and so that source changes don't invalidate our downloaded layer

* Generator resource action test breaks with unused imports fixes #1893 (#1894)

* Generator resource action test breaks with unused imports fixes #1893

* break packr cache

* fix broken test

* update deps (#1896)

* update deps

* update envy

* update meta

* switch to tags/v3 for consistency (#1901)

* update helpers/tags

* update validate

* try to fix mismatched imports (#1921)

* fixes more broken semantic import paths (#1925)

* adding a few packages to replace

* Replace Azure badge with Github actions badge (#1920)

Co-authored-by: Antonio Pagano <[email protected]>

* changing the packages to be replaced (#1928)

* changing the packages to be replaced

* adding back gobuffalo/uuid change

* Merging master (#1936)

* v0.16.1 (#1929)

* merge changes from buffalo-cli into main repo

* cache deps before building and copying source (#1884)

cache deps before building and copying source so that we don't need to re-download as much
and so that source changes don't invalidate our downloaded layer

* Generator resource action test breaks with unused imports fixes #1893 (#1894)

* Generator resource action test breaks with unused imports fixes #1893

* break packr cache

* fix broken test

* update deps (#1896)

* update deps

* update envy

* update meta

* switch to tags/v3 for consistency (#1901)

* update helpers/tags

* update validate

* try to fix mismatched imports (#1921)

* fixes more broken semantic import paths (#1925)

* adding a few packages to replace

* Replace Azure badge with Github actions badge (#1920)

Co-authored-by: Antonio Pagano <[email protected]>

* changing the packages to be replaced (#1928)

* changing the packages to be replaced

* adding back gobuffalo/uuid change

Co-authored-by: Mark Bates <[email protected]>
Co-authored-by: Dr Nic Williams <[email protected]>
Co-authored-by: HD Moore <[email protected]>
Co-authored-by: Stanislas Michalak <[email protected]>

* Add stack trace to ErrPanic event for easier debugging and monitoring (#1930)

Co-authored-by: Canh Nguyen <[email protected]>

* Modifies our docker file to pull buffalo binary from releases. (#1935)

* fixing docker image to use github binary

Co-authored-by: Mark Bates <[email protected]>
Co-authored-by: Dr Nic Williams <[email protected]>
Co-authored-by: HD Moore <[email protected]>
Co-authored-by: Stanislas Michalak <[email protected]>
Co-authored-by: xuancanh <[email protected]>
Co-authored-by: Canh Nguyen <[email protected]>

* Update js template to support font awesome (#1933)

* v0.16.1 (#1929)

* merge changes from buffalo-cli into main repo

* cache deps before building and copying source (#1884)

cache deps before building and copying source so that we don't need to re-download as much
and so that source changes don't invalidate our downloaded layer

* Generator resource action test breaks with unused imports fixes #1893 (#1894)

* Generator resource action test breaks with unused imports fixes #1893

* break packr cache

* fix broken test

* update deps (#1896)

* update deps

* update envy

* update meta

* switch to tags/v3 for consistency (#1901)

* update helpers/tags

* update validate

* try to fix mismatched imports (#1921)

* fixes more broken semantic import paths (#1925)

* adding a few packages to replace

* Replace Azure badge with Github actions badge (#1920)

Co-authored-by: Antonio Pagano <[email protected]>

* changing the packages to be replaced (#1928)

* changing the packages to be replaced

* adding back gobuffalo/uuid change

Co-authored-by: Mark Bates <[email protected]>
Co-authored-by: Dr Nic Williams <[email protected]>
Co-authored-by: HD Moore <[email protected]>
Co-authored-by: Stanislas Michalak <[email protected]>

* Add stack trace to ErrPanic event for easier debugging and monitoring (#1930)

Co-authored-by: Canh Nguyen <[email protected]>

* Update js template to support font awesome

The latest version of font-awesome requires the js file to also be present for a glyph to work.  To see this work, add this code to any page template:

```html
<h3>
<a href=#" target="_blank"><i class="fab fa-twitter-square share" aria-hidden="true"></i></a>
</h3>
```

Without this JS file, the glyph will not render.

Co-authored-by: Antonio Pagano <[email protected]>
Co-authored-by: Mark Bates <[email protected]>
Co-authored-by: Dr Nic Williams <[email protected]>
Co-authored-by: HD Moore <[email protected]>
Co-authored-by: Stanislas Michalak <[email protected]>
Co-authored-by: xuancanh <[email protected]>
Co-authored-by: Canh Nguyen <[email protected]>

* Fixes generated package.json and resources generator (#1944)

* v0.16.1 (#1929)

* merge changes from buffalo-cli into main repo

* cache deps before building and copying source (#1884)

cache deps before building and copying source so that we don't need to re-download as much
and so that source changes don't invalidate our downloaded layer

* Generator resource action test breaks with unused imports fixes #1893 (#1894)

* Generator resource action test breaks with unused imports fixes #1893

* break packr cache

* fix broken test

* update deps (#1896)

* update deps

* update envy

* update meta

* switch to tags/v3 for consistency (#1901)

* update helpers/tags

* update validate

* try to fix mismatched imports (#1921)

* fixes more broken semantic import paths (#1925)

* adding a few packages to replace

* Replace Azure badge with Github actions badge (#1920)

Co-authored-by: Antonio Pagano <[email protected]>

* changing the packages to be replaced (#1928)

* changing the packages to be replaced

* adding back gobuffalo/uuid change

Co-authored-by: Mark Bates <[email protected]>
Co-authored-by: Dr Nic Williams <[email protected]>
Co-authored-by: HD Moore <[email protected]>
Co-authored-by: Stanislas Michalak <[email protected]>

* Add stack trace to ErrPanic event for easier debugging and monitoring (#1930)

Co-authored-by: Canh Nguyen <[email protected]>

* Modifies our docker file to pull buffalo binary from releases. (#1935)

* fixing docker image to use github binary

* Bump pop version (#1937)

* adding resource and new app generator fixes

* fixing buffalo generator to use v5 of pop

* updating popper and removing repeated version of webpack-manifest

* updating old tooling on the JS side

* updating webpack version

* updating node dependencies on fixture to remove github warnings

Co-authored-by: Mark Bates <[email protected]>
Co-authored-by: Dr Nic Williams <[email protected]>
Co-authored-by: HD Moore <[email protected]>
Co-authored-by: Stanislas Michalak <[email protected]>
Co-authored-by: xuancanh <[email protected]>
Co-authored-by: Canh Nguyen <[email protected]>

* updating dockerfile to use v0.16.3

* packing

* Adding new template for codeclimate code analysis (#1946)

* adding new template for codeclimate code analysis

* packing

* Updates our coke app package.json and Yarn (#1947)

* updating package.lock on the lock sample

* removing old pop plugin

* adding task to the fixers

* removing the fixer part

* Removes old buffalo-pop plugin (#1948)

* removes old buffalo-pop plugin

* naming change

* using filepath for auto render files (#1951)

* Bugfix c.Error http code (#1952)

* fixes error code not being logged

* adding tests for the status code when error handled fires

* Allows to set test timeout (#1953)

* allowing to pass timeout to the test command

* packing

* Fixes plush to use now plush/v4 (#1954)

* Adding packr files (#1956)

* Missing comments on the Plugins struct (#1958)

* Adding packr files

* adding a couple of comments missing

* fixing mispell package (#1960)

* Task #1941 (#1943)

* covering non id cases on the route name generator

* fixing broken tests

* adding a few more test cases

* moving to just use a string for simplified ID

* bumping version

* packing

* use go 1.14 for building goreleaser binaries (#1962)

* adds an extra file to our releases that will be pulled by our docker images build process (#1964)

* cleaning some docker issues (#1966)

* Fix GO111MODULE value in build Docker images (#1970)

* Add in GZIP compression to file serving (#1969)

* Add in GZIP compression to file serving

* Add option to control gzip

* Added genny support for CircleCI as a CI provider. (#1972)

* Added genny support for CircleCI as a CI provider.

* Updated circleci template

* Also fixed Travis and GitLab templates

* removing helpers from the Go template Engine (#1971)

* adding next version

* packing

* making codeclimate ignore packr files

* adding direct version on the docker build

* fixing plugin installation

* bumping version

* Binding refactoring (#1975)

* refactoring binding a bit

* adding tests for null time decoder

* removing unneeded variable

* little bit of name changes

* moving RequestTypeBinder interface

* adding some missing comments

* advancing on Marks recommendations. 1st step is to reduce the indirect behavior on the interface

* back to locks

* adding lock on Exec

* adding those missing tests

* moving time formats to the decoders section

* added autoprefixer for bootstrap compilation (#1990)

* Add batch mail sending (#1815)

* Add batch mail sending

* fix formatting

* fix batch send

* fix single mail check

Co-authored-by: Stanislas Michalak <[email protected]>
Co-authored-by: Antonio Pagano <[email protected]>

* Updates jQuery Dependency (#1995)

* updating jquery and bootstrap to pass a security warning we have in the repo

* changing docker version for next release

* packing

* removing extra file from the releaser

* adding some missing comments

* removing unused fields

Co-authored-by: Mark Bates <[email protected]>
Co-authored-by: Dr Nic Williams <[email protected]>
Co-authored-by: HD Moore <[email protected]>
Co-authored-by: Stanislas Michalak <[email protected]>
Co-authored-by: xuancanh <[email protected]>
Co-authored-by: Canh Nguyen <[email protected]>
Co-authored-by: Cory LaNou <[email protected]>
Co-authored-by: Vlad Artamonov <[email protected]>
Co-authored-by: Vincent Chu <[email protected]>
Co-authored-by: James Turnbull <[email protected]>
Co-authored-by: arunsworld <[email protected]>
Co-authored-by: Ilya Krasheninnikov <[email protected]>
  • Loading branch information
13 people authored May 25, 2020
1 parent 0ffd608 commit b30b199
Show file tree
Hide file tree
Showing 32 changed files with 1,155 additions and 810 deletions.
4 changes: 2 additions & 2 deletions Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ RUN npm install -g --no-progress yarn \
RUN curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin v1.24.0

# Pulling docker binary from releases
RUN wget https://github.com/gobuffalo/buffalo/releases/download/v0.16.8/buffalo_0.16.8_Linux_x86_64.tar.gz \
&& tar -xzf buffalo_0.16.8_Linux_x86_64.tar.gz \
RUN wget https://github.com/gobuffalo/buffalo/releases/download/v0.16.9/buffalo_0.16.9_Linux_x86_64.tar.gz \
&& tar -xzf buffalo_0.16.9_Linux_x86_64.tar.gz \
&& mv buffalo $(go env GOPATH)/bin/buffalo

RUN go get github.com/gobuffalo/buffalo-pop/v2
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.slim.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ RUN npm i -g --no-progress yarn \
&& yarn config set yarn-offline-mirror-pruning true

# Pulling docker binary from releases
RUN wget https://github.com/gobuffalo/buffalo/releases/download/v0.16.8/buffalo_0.16.8_Linux_x86_64.tar.gz \
&& tar -xzf buffalo_0.16.8_Linux_x86_64.tar.gz \
RUN wget https://github.com/gobuffalo/buffalo/releases/download/vv0.16.9/buffalo_v0.16.9_Linux_x86_64.tar.gz \
&& tar -xzf buffalo_v0.16.9_Linux_x86_64.tar.gz \
&& mv buffalo $(go env GOPATH)/bin/buffalo

RUN go get github.com/gobuffalo/buffalo-pop/v2
Expand Down
172 changes: 31 additions & 141 deletions binding/binding.go
Original file line number Diff line number Diff line change
@@ -1,71 +1,56 @@
package binding

import (
"encoding/json"
"encoding/xml"
"fmt"
"net/http"
"strings"
"sync"
"time"

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

// 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
var (
// MaxFileMemory can be used to set the maximum size, in bytes, for files to be
// stored in memory during uploaded for multipart requests.
// See https://golang.org/pkg/net/http/#Request.ParseMultipartForm for more
// information on how this impacts file uploads.
MaxFileMemory int64 = 5 * 1024 * 1024

// CustomTypeDecoder converts a custom type from the request insto its exact type.
type CustomTypeDecoder func([]string) (interface{}, error)

// binders is a map of the defined content-type related binders.
var binders = map[string]Binder{}
formDecoder = formam.NewDecoder(&formam.DecoderOptions{
TagName: "form",
IgnoreUnknownKeys: true,
})

var decoder *formam.Decoder
var lock = &sync.Mutex{}
var timeFormats = []string{
time.RFC3339,
"01/02/2006",
"2006-01-02",
"2006-01-02T15:04",
time.ANSIC,
time.UnixDate,
time.RubyDate,
time.RFC822,
time.RFC822Z,
time.RFC850,
time.RFC1123,
time.RFC1123Z,
time.RFC3339Nano,
time.Kitchen,
time.Stamp,
time.StampMilli,
time.StampMicro,
time.StampNano,
}
// BaseRequestBinder is an instance of the requeBinder, 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,
},
JSONContentTypeBinder{},
XMLRequestTypeBinder{},
FileRequestTypeBinder{
decoder: formDecoder,
},
)
)

// RegisterTimeFormats allows to add custom time layouts that
// the binder will be able to use for decoding.
func RegisterTimeFormats(layouts ...string) {
timeFormats = append(layouts, timeFormats...)
decoders.RegisterTimeFormats(layouts...)
}

// RegisterCustomDecoder allows to define custom type decoders.
// 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)
decoder.RegisterCustomType(rawFunc, types, fields)
formDecoder.RegisterCustomType(rawFunc, types, fields)
}

// Register maps a request Content-Type (application/json)
// to a Binder.
func Register(contentType string, fn Binder) {
lock.Lock()
defer lock.Unlock()

binders[strings.ToLower(contentType)] = fn
BaseRequestBinder.Register(contentType, fn)
}

// Exec will bind the interface to the request.Body. The type of binding
Expand All @@ -74,100 +59,5 @@ func Register(contentType string, fn Binder) {
// 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 {
if ba, ok := value.(Bindable); ok {
return ba.Bind(req)
}

ct := httpx.ContentType(req)
if ct == "" {
return fmt.Errorf("blank content type")
}
if b, ok := binders[ct]; ok {
return b(req, value)
}
return fmt.Errorf("could not find a binder for %s", ct)
}

func init() {
decoder = formam.NewDecoder(&formam.DecoderOptions{
TagName: "form",
IgnoreUnknownKeys: true,
})

decoder.RegisterCustomType(func(vals []string) (interface{}, error) {
return parseTime(vals)
}, []interface{}{time.Time{}}, nil)

decoder.RegisterCustomType(func(vals []string) (interface{}, error) {
var ti nulls.Time

t, err := parseTime(vals)
if err != nil {
return ti, err
}
ti.Time = t
ti.Valid = true

return ti, nil
}, []interface{}{nulls.Time{}}, nil)

sb := func(req *http.Request, i interface{}) error {
err := req.ParseForm()
if err != nil {
return err
}

if err := decoder.Decode(req.Form, i); err != nil {
return err
}
return nil
}

binders["application/html"] = sb
binders["text/html"] = sb
binders["application/x-www-form-urlencoded"] = sb
binders["html"] = sb
}

func init() {
jb := func(req *http.Request, value interface{}) error {
return json.NewDecoder(req.Body).Decode(value)
}

binders["application/json"] = jb
binders["text/json"] = jb
binders["json"] = jb
}

func init() {
xb := func(req *http.Request, value interface{}) error {
return xml.NewDecoder(req.Body).Decode(value)
}

binders["application/xml"] = xb
binders["text/xml"] = xb
binders["xml"] = xb
}

func parseTime(vals []string) (time.Time, error) {
var t time.Time
var err error

// don't try to parse empty time values, it will raise an error
if len(vals) == 0 || vals[0] == "" {
return t, nil
}

for _, layout := range timeFormats {
t, err = time.Parse(layout, vals[0])
if err == nil {
return t, nil
}
}

if err != nil {
return t, err
}

return t, nil
return BaseRequestBinder.Exec(req, value)
}
40 changes: 0 additions & 40 deletions binding/binding_custom_decoder_test.go

This file was deleted.

94 changes: 49 additions & 45 deletions binding/binding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,73 @@ package binding

import (
"net/http"
"net/url"
"testing"
"time"

"github.com/stretchr/testify/require"
)

type blogPost struct {
Tags []string
Dislikes int
Likes int32
}

func Test_Register(t *testing.T) {
r := require.New(t)
l := len(binders)

Register("foo/bar", func(*http.Request, interface{}) error {
return nil
})
r.Len(binders, l+1)
}

func TestParseTimeErrorParsing(t *testing.T) {
r := require.New(t)
_, err := parseTime([]string{"this is sparta"})
r.Error(err)
}

func TestParseTime(t *testing.T) {
r.NotNil(BaseRequestBinder.binders["foo/bar"])

r := require.New(t)
req, err := http.NewRequest("POST", "/", nil)
r.NoError(err)

testCases := []struct {
input string
expected time.Time
expectErr bool
}{
{
input: "2017-01-01",
expected: time.Date(2017, time.January, 1, 0, 0, 0, 0, time.UTC),
expectErr: false,
},
{
input: "2018-07-13T15:34",
expected: time.Date(2018, time.July, 13, 15, 34, 0, 0, time.UTC),
expectErr: false,
},
{
input: "2018-20-10T30:15",
expected: time.Time{},
expectErr: true,
},
req.Header.Set("Content-Type", "foo/bar")
req.Form = url.Values{
"Tags": []string{"AAA"},
"Likes": []string{"12"},
"Dislikes": []string{"1000"},
}

for _, tc := range testCases {
tt, err := parseTime([]string{tc.input})
if !tc.expectErr {
r.NoError(err)
}
r.Equal(tc.expected, tt)
}
}
req.ParseForm()

var post blogPost
r.NoError(Exec(req, &post))

func TestParseTimeConflicting(t *testing.T) {
RegisterTimeFormats("2006-02-01")
r.Equal([]string(nil), post.Tags)
r.Equal(int32(0), post.Likes)
r.Equal(0, post.Dislikes)

}

func Test_RegisterCustomDecoder(t *testing.T) {
r := require.New(t)
tt, err := parseTime([]string{"2017-01-10"})

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

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

post := blogPost{}
req, err := http.NewRequest("POST", "/", nil)
r.NoError(err)
expected := time.Date(2017, time.October, 1, 0, 0, 0, 0, time.UTC)
r.Equal(expected, tt)

req.Header.Set("Content-Type", "application/html")
req.Form = url.Values{
"Tags": []string{"AAA"},
"Likes": []string{"12"},
"Dislikes": []string{"1000"},
}
req.ParseForm()

r.NoError(Exec(req, &post))
r.Equal([]string{"X"}, post.Tags)
r.Equal(int32(12), post.Likes)
r.Equal(0, post.Dislikes)
}
Loading

0 comments on commit b30b199

Please sign in to comment.