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

v0.18.7 #2255

Merged
merged 26 commits into from
May 5, 2022
Merged

v0.18.7 #2255

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
22947b1
intermediately, introduce Home struct
sio4 Mar 22, 2022
211ee68
adapted to the new struct (with small bugfix)
sio4 Mar 23, 2022
16d6f7c
fixed issues related to multi-homing and task {routes,middleware}
sio4 Mar 24, 2022
efeb149
simplified, renamed the multi-homing function (Host -> VirtualHost)
sio4 Mar 24, 2022
999fb9d
Bump github.com/gobuffalo/plush/v4 from 4.1.9 to 4.1.10
dependabot[bot] Mar 25, 2022
f330f9b
Merge pull request #2226 from gochigo/fix-multi-homing
paganotoni Apr 2, 2022
b9dc28b
Bump github.com/gobuffalo/flect from 0.2.4 to 0.2.5
dependabot[bot] Apr 4, 2022
f25bbee
Bump github.com/BurntSushi/toml from 1.0.0 to 1.1.0
dependabot[bot] Apr 5, 2022
edcda04
Bump actions/stale from 4 to 5
dependabot[bot] Apr 8, 2022
3518513
Bump actions/setup-go from 2 to 3
dependabot[bot] Apr 8, 2022
4bb1530
Merge pull request #2237 from gobuffalo/dependabot/github_actions/dev…
paganotoni Apr 8, 2022
6531d1c
Merge pull request #2236 from gobuffalo/dependabot/github_actions/dev…
paganotoni Apr 8, 2022
f53c924
HTTPError Error() avoid nil pointer dereference on nil Cause
saurori Apr 15, 2022
1acf05b
HTTPError Error() return when Cause is nil
saurori Apr 16, 2022
be59b08
Merge pull request #2238 from saurori/nil-error
paganotoni Apr 16, 2022
8fcc6a9
Merge branch 'main' into development
paganotoni Apr 16, 2022
82c6787
task: adding next version number
paganotoni Apr 16, 2022
9d73433
Bump github.com/gobuffalo/pop/v6 from 6.0.1 to 6.0.2
dependabot[bot] Apr 18, 2022
2ccfb9f
hardening DefaultContext to make it panic-free
sio4 Apr 21, 2022
9195c04
added input/status checks, testcases, and comments for road-to-v1
sio4 Apr 18, 2022
11507d3
added sync for testcases. currently execution is not guaranteed for P…
sio4 Apr 18, 2022
4398c16
Remove ioutil and replace with io/os functions
Apr 28, 2022
d78ef76
Fix logging of where application is bound
hut8 Apr 25, 2022
7390982
Revision as per @sio4
hut8 Apr 26, 2022
0473e68
Merge branch 'main' into development
paganotoni May 4, 2022
1b38e5b
task: updating version number
paganotoni May 4, 2022
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
16 changes: 15 additions & 1 deletion default_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import (
var _ Context = &DefaultContext{}
var _ context.Context = &DefaultContext{}

// TODO(sio4): #road-to-v1 - make DefaultContext private
// and only allow it to be generated by App.newContext() or any similar.

// DefaultContext is, as its name implies, a default
// implementation of the Context interface.
type DefaultContext struct {
Expand Down Expand Up @@ -67,16 +70,22 @@ 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{}) {
if d.data == nil {
d.data = &sync.Map{}
}
d.data.Store(key, value)
}

// Value that has previously stored on the context.
func (d *DefaultContext) Value(key interface{}) interface{} {
if k, ok := key.(string); ok {
if k, ok := key.(string); ok && d.data != nil {
if v, ok := d.data.Load(k); ok {
return v
}
}
if d.Context == nil {
return nil
}
return d.Context.Value(key)
}

Expand Down Expand Up @@ -235,6 +244,11 @@ 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{}{}

if d.data == nil {
return m
}

d.data.Range(func(k, v interface{}) bool {
s, ok := k.(string)
if !ok {
Expand Down
81 changes: 80 additions & 1 deletion default_context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ func Test_DefaultContext_GetSet(t *testing.T) {
r.Equal("Mark", c.Value("name").(string))
}

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

c.Set("name", "Yonghwan")
r.NotNil(c.Value("name"))
r.Equal("Yonghwan", c.Value("name").(string))
}

func Test_DefaultContext_Value(t *testing.T) {
r := require.New(t)
c := basicContext()
Expand All @@ -151,7 +160,12 @@ func Test_DefaultContext_Value(t *testing.T) {
c.Set("name", "Mark")
r.NotNil(c.Value("name"))
r.Equal("Mark", c.Value("name").(string))
r.Equal("Mark", c.Value("name").(string))
}

func Test_DefaultContext_Value_Unconfigured(t *testing.T) {
r := require.New(t)
c := DefaultContext{}
r.Nil(c.Value("name"))
}

func Test_DefaultContext_Render(t *testing.T) {
Expand Down Expand Up @@ -301,3 +315,68 @@ func Test_DefaultContext_Bind_JSON(t *testing.T) {

r.Equal("Mark", user.FirstName)
}

func Test_DefaultContext_Data(t *testing.T) {
r := require.New(t)
c := basicContext()

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

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

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

func Test_DefaultContext_String(t *testing.T) {
r := require.New(t)
c := basicContext()
c.Set("name", "Buffalo")
c.Set("language", "go")

r.EqualValues("language: go\n\nname: Buffalo", c.String())
}

func Test_DefaultContext_String_EmptyData(t *testing.T) {
r := require.New(t)
c := basicContext()
r.EqualValues("", c.String())
}

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

r.EqualValues("", c.String())
}

func Test_DefaultContext_MarshalJSON(t *testing.T) {
r := require.New(t)
c := basicContext()
c.Set("name", "Buffalo")
c.Set("language", "go")

jb, err := c.MarshalJSON()
r.NoError(err)
r.EqualValues(`{"language":"go","name":"Buffalo"}`, string(jb))
}

func Test_DefaultContext_MarshalJSON_EmptyData(t *testing.T) {
r := require.New(t)
c := basicContext()

jb, err := c.MarshalJSON()
r.NoError(err)
r.EqualValues(`{}`, string(jb))
}

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

jb, err := c.MarshalJSON()
r.NoError(err)
r.EqualValues(`{}`, string(jb))
}
4 changes: 2 additions & 2 deletions plugins/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package plugins

import (
"context"
"io/ioutil"
"os"
"strings"
"testing"
"time"
Expand All @@ -20,7 +20,7 @@ func TestAskBin_respectsTimeout(t *testing.T) {
return
}

if fileEntries, err := ioutil.ReadDir(from); err == nil {
if fileEntries, err := os.ReadDir(from); err == nil {
found := false
for _, e := range fileEntries {
if strings.HasPrefix(e.Name(), "buffalo-") {
Expand Down
18 changes: 9 additions & 9 deletions router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package buffalo

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -98,7 +98,7 @@ func Test_Mount_Buffalo(t *testing.T) {
r.NoError(err)
res, err := http.DefaultClient.Do(req)
r.NoError(err)
b, _ := ioutil.ReadAll(res.Body)
b, _ := io.ReadAll(res.Body)
r.Equal(fmt.Sprintf("%s - %s/", m, u), string(b))
}
}
Expand All @@ -123,7 +123,7 @@ func Test_Mount_Buffalo_on_Group(t *testing.T) {
r.NoError(err)
res, err := http.DefaultClient.Do(req)
r.NoError(err)
b, _ := ioutil.ReadAll(res.Body)
b, _ := io.ReadAll(res.Body)
r.Equal(fmt.Sprintf("%s - %s/", m, u), string(b))
}
}
Expand Down Expand Up @@ -158,7 +158,7 @@ func Test_Mount_Handler(t *testing.T) {
r.NoError(err)
res, err := http.DefaultClient.Do(req)
r.NoError(err)
b, _ := ioutil.ReadAll(res.Body)
b, _ := io.ReadAll(res.Body)
r.Equal(fmt.Sprintf("%s - %s/", m, u), string(b))
}
}
Expand Down Expand Up @@ -197,7 +197,7 @@ func Test_PreHandlers(t *testing.T) {
r.NoError(err)
res, err := http.DefaultClient.Do(req)
r.NoError(err)
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
r.NoError(err)
r.Equal(v.Code, res.StatusCode)
r.Equal(v.Result, string(b))
Expand Down Expand Up @@ -242,7 +242,7 @@ func Test_PreWares(t *testing.T) {
r.NoError(err)
res, err := http.DefaultClient.Do(req)
r.NoError(err)
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
r.NoError(err)
r.Equal(v.Code, res.StatusCode)
r.Equal(v.Result, string(b))
Expand All @@ -269,7 +269,7 @@ func Test_Router(t *testing.T) {
r.NoError(err)
res, err := http.DefaultClient.Do(req)
r.NoError(err)
b, _ := ioutil.ReadAll(res.Body)
b, _ := io.ReadAll(res.Body)
r.Equal(fmt.Sprintf("%s|/router/tests", v), string(b))
}
}
Expand Down Expand Up @@ -552,7 +552,7 @@ func Test_Resource(t *testing.T) {
r.NoError(err)
res, err := c.Do(req)
r.NoError(err)
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
r.NoError(err)
r.Equal(test.Result, string(b))
}
Expand Down Expand Up @@ -710,7 +710,7 @@ func Test_ResourceOnResource(t *testing.T) {
r.NoError(err)
res, err := c.Do(req)
r.NoError(err)
b, err := ioutil.ReadAll(res.Body)
b, err := io.ReadAll(res.Body)
r.NoError(err)
r.Equal(test.Result, string(b))
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package runtime

// Version is the current version of the buffalo binary
var Version = "v0.18.6"
var Version = "v0.18.7"
5 changes: 2 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import (
func (a *App) Serve(srvs ...servers.Server) error {
var wg sync.WaitGroup

// FIXME: this information is not correct.
// It needs to be fixed as we support multiple servers.
a.Logger.Infof("starting application at http://%s", a.Options.Addr)
a.Logger.Debug("starting application")

payload := events.Payload{
"app": a,
Expand Down Expand Up @@ -98,6 +96,7 @@ func (a *App) Serve(srvs ...servers.Server) error {

for _, s := range srvs {
s.SetAddr(a.Addr)
a.Logger.Infof("starting %s", s)
wg.Add(1)
go func(s servers.Server) {
defer wg.Done()
Expand Down
6 changes: 6 additions & 0 deletions servers/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package servers

import (
"context"
"fmt"
"net"
"net/http"
)
Expand All @@ -19,6 +20,11 @@ func (s *Listener) SetAddr(addr string) {
}
}

// String returns a string representation of a Listener
func (s *Listener) String() string {
return fmt.Sprintf("listener on %s", s.Server.Addr)
}

// Start the server
func (s *Listener) Start(c context.Context, h http.Handler) error {
s.Handler = h
Expand Down
6 changes: 6 additions & 0 deletions servers/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package servers

import (
"context"
"fmt"
"net/http"
)

Expand All @@ -17,6 +18,11 @@ func (s *Simple) SetAddr(addr string) {
}
}

// String returns a string representation of a Simple server
func (s *Simple) String() string {
return fmt.Sprintf("simple server on %s", s.Server.Addr)
}

// Start the server
func (s *Simple) Start(c context.Context, h http.Handler) error {
s.Handler = h
Expand Down
6 changes: 6 additions & 0 deletions servers/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package servers

import (
"context"
"fmt"
"net/http"
)

Expand All @@ -19,6 +20,11 @@ func (s *TLS) SetAddr(addr string) {
}
}

// String returns a string representation of a Listener
func (s *TLS) String() string {
return fmt.Sprintf("TLS server on %s", s.Server.Addr)
}

// Start the server
func (s *TLS) Start(c context.Context, h http.Handler) error {
s.Handler = h
Expand Down
Loading